def isIPAddress(addr, family=AF_INET):
    """
    Determine whether the given string represents an IP address of the given
    family; by default, an IPv4 address.

    @type addr: C{str}
    @param addr: A string which may or may not be the decimal dotted
        representation of an IPv4 address.

    @param family: The address family to test for; one of the C{AF_*} constants
        from the L{socket} module.  (This parameter has only been available
        since Twisted 17.1.0; previously L{isIPAddress} could only test for IPv4
        addresses.)
    @type family: C{int}

    @rtype: C{bool}
    @return: C{True} if C{addr} represents an IPv4 address, C{False} otherwise.
    """
    if isinstance(addr, bytes):
        try:
            addr = addr.decode("ascii")
        except UnicodeDecodeError:
            return False
    if family == AF_INET6:
        # On some platforms, inet_ntop fails unless the scope ID is valid; this
        # is a test for whether the given string *is* an IP address, so strip
        # any potential scope ID before checking.
        addr = addr.split(u"%", 1)[0]
    elif family == AF_INET:
        # On Windows, where 3.5+ implement inet_pton, "0" is considered a valid
        # IPv4 address, but we want to ensure we have all 4 segments.
        if addr.count(u".") != 3:
            return False
    else:
        raise ValueError("unknown address family {!r}".format(family))
    try:
        # This might be a native implementation or the one from
        # twisted.python.compat.
        inet_pton(family, addr)
    except (ValueError, error):
        return False
    return True

    Determine whether the given string represents an IP address of the given
    family; by default, an IPv4 address.

    @type addr: C{str}
    @param addr: A string which may or may not be the decimal dotted
        representation of an IPv4 address.

    @param family: The address family to test for; one of the C{AF_*} constants
        from the L{socket} module.  (This parameter has only been available
        since Twisted 17.1.0; previously L{isIPAddress} could only test for IPv4
        addresses.)
    @type family: C{int}

    @rtype: C{bool}
    @return: C{True} if C{addr} represents an IPv4 address, C{False} otherwise.
    
stackoverflow/venv/lib/python3.6/site-packages/twisted/internet/abstract.py