pytoolbox.network.ip module¶
- pytoolbox.network.ip.ip_address(address)[source]¶
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 or IPv6Address object.
- Raises:
- ValueError: if the address passed isn’t either a v4 or a v6
address
- pytoolbox.network.ip.IPSocket(socket)[source]¶
This helper create a dictionary containing address and port from a parsed IP address string. Throws InvalidIPSocketError in case of failure.
Example usage
>>> IPSocket('gaga:gogo') Traceback (most recent call last): ... pytoolbox.exceptions.InvalidIPSocketError: gaga:gogo is not a valid IP socket. >>> >>> from pytoolbox.unittest import asserts >>> asserts.dict_equal( ... IPSocket('239.232.0.222:5004'), ... {'ip': '239.232.0.222', 'port': 5004})
Warning
TODO IPv6 ready : >>> IPSocket(‘[2001:0db8:0000:0000:0000:ff00:0042]:8329’)