Detects whether the hostname given is an IPv4 or IPv6 address. Also detects IPv6 addresses with Zone IDs. :param str hostname: Hostname to examine. :return: True if the hostname is an IP address, False otherwise.
(hostname: str | bytes)
| 435 | |
| 436 | |
| 437 | def is_ipaddress(hostname: str | bytes) -> bool: |
| 438 | """Detects whether the hostname given is an IPv4 or IPv6 address. |
| 439 | Also detects IPv6 addresses with Zone IDs. |
| 440 | |
| 441 | :param str hostname: Hostname to examine. |
| 442 | :return: True if the hostname is an IP address, False otherwise. |
| 443 | """ |
| 444 | if isinstance(hostname, bytes): |
| 445 | # IDN A-label bytes are ASCII compatible. |
| 446 | hostname = hostname.decode("ascii") |
| 447 | return bool(_IPV4_RE.match(hostname) or _BRACELESS_IPV6_ADDRZ_RE.match(hostname)) |
| 448 | |
| 449 | |
| 450 | def _is_key_file_encrypted(key_file: str) -> bool: |
no outgoing calls
no test coverage detected