Take an IP string/int and return an object of the correct type. Args: address: A string or integer, the IP address. Either IPv4 or IPv6 addresses may be supplied; integers less than 2**32 will be considered to be IPv4 by default. Returns: An IPv4Address
(address)
| 23 | |
| 24 | |
| 25 | def ip_address(address): |
| 26 | """Take an IP string/int and return an object of the correct type. |
| 27 | |
| 28 | Args: |
| 29 | address: A string or integer, the IP address. Either IPv4 or |
| 30 | IPv6 addresses may be supplied; integers less than 2**32 will |
| 31 | be considered to be IPv4 by default. |
| 32 | |
| 33 | Returns: |
| 34 | An IPv4Address or IPv6Address object. |
| 35 | |
| 36 | Raises: |
| 37 | ValueError: if the *address* passed isn't either a v4 or a v6 |
| 38 | address |
| 39 | |
| 40 | """ |
| 41 | try: |
| 42 | return IPv4Address(address) |
| 43 | except (AddressValueError, NetmaskValueError): |
| 44 | pass |
| 45 | |
| 46 | try: |
| 47 | return IPv6Address(address) |
| 48 | except (AddressValueError, NetmaskValueError): |
| 49 | pass |
| 50 | |
| 51 | raise ValueError(f'{address!r} does not appear to be an IPv4 or IPv6 address') |
| 52 | |
| 53 | |
| 54 | def ip_network(address, strict=True): |
nothing calls this directly
no test coverage detected
searching dependent graphs…