Take an IP string/int and return an object of the correct type. Args: address: A string or integer, the IP network. Either IPv4 or IPv6 networks may be supplied; integers less than 2**32 will be considered to be IPv4 by default. Returns: An IPv4Network
(address, strict=True)
| 52 | |
| 53 | |
| 54 | def ip_network(address, strict=True): |
| 55 | """Take an IP string/int and return an object of the correct type. |
| 56 | |
| 57 | Args: |
| 58 | address: A string or integer, the IP network. Either IPv4 or |
| 59 | IPv6 networks may be supplied; integers less than 2**32 will |
| 60 | be considered to be IPv4 by default. |
| 61 | |
| 62 | Returns: |
| 63 | An IPv4Network or IPv6Network object. |
| 64 | |
| 65 | Raises: |
| 66 | ValueError: if the string passed isn't either a v4 or a v6 |
| 67 | address. Or if the network has host bits set. |
| 68 | |
| 69 | """ |
| 70 | try: |
| 71 | return IPv4Network(address, strict) |
| 72 | except (AddressValueError, NetmaskValueError): |
| 73 | pass |
| 74 | |
| 75 | try: |
| 76 | return IPv6Network(address, strict) |
| 77 | except (AddressValueError, NetmaskValueError): |
| 78 | pass |
| 79 | |
| 80 | raise ValueError(f'{address!r} does not appear to be an IPv4 or IPv6 network') |
| 81 | |
| 82 | |
| 83 | def ip_interface(address): |
nothing calls this directly
no test coverage detected
searching dependent graphs…