def is_ipaddress()

in elastic_transport/_utils.py [0:0]


def is_ipaddress(hostname: Union[str, bytes]) -> bool:
    """Detects whether the hostname given is an IPv4 or IPv6 address.
    Also detects IPv6 addresses with Zone IDs.
    """
    # Copied from urllib3. License: MIT
    if isinstance(hostname, bytes):
        # IDN A-label bytes are ASCII compatible.
        hostname = hostname.decode("ascii")
    hostname = hostname.strip("[]")
    return bool(IPV4_RE.match(hostname) or BRACELESS_IPV6_ADDRZ_RE.match(hostname))