def ip_in_networks(
    ip_addr: str, networks: Iterable[ipaddress.IPv4Network | ipaddress.IPv6Network]
):
    """
    Checks if `ip_addr` is contained within any of the networks in `networks`

    If ip_addr is in any of the provided networks, return the first network that matches.
    If not, return False

    Both ipv6 and ipv4 are supported
    """
    ip = ipaddress.ip_address(ip_addr)
    for network in networks:
        if ip in network:
            return network
    return False

    Checks if `ip_addr` is contained within any of the networks in `networks`

    If ip_addr is in any of the provided networks, return the first network that matches.
    If not, return False

    Both ipv6 and ipv4 are supported
    
binderhub/utils.py