1.3 IPAddr Objects

An IPAddr object represents an IPv4 or IPv6 address.

class IPAddr( address)
The constructor takes either a string address, which must be a string representation of either an IPv4 or IPv6 address, or an integer representation of the address. IPv6 addresses are only accepted if ipv6_enabled() returns True.

Examples:

>>> addr1 = IPAddr('192.160.1.1')
>>> addr2 = IPAddr('2001:db8::1428:57ab')
>>> addr3 = IPAddr('::ffff:12.34.56.78')
>>> addr4 = IPAddr(0xffffffff)
>>> addr5 = IPAddr(0xffffffffffffffffffffffffffffffff)

Supported operations:

Operation Result
addr1 < addr2 addr1 is considered less than addr2 if the 128-bit representation of addr1 is less than addr2
int(addr1) The integer representation of addr

Instance methods:

ipv6( )
Return True if the address is an IPv6 address, False otherwise.

__str__( )
For an address addr, str(addr) returns a human-readable representation of that address.