Python 3.3+ipaddressterm
ipaddress.IPv6Network
networks
The IPv6 network class: the same operations as IPv4Network, but for 128-bit addresses and huge ranges.
Syntax
ipaddress.IPv6Network(address, strict=True)
A typical /64 subnet holds 2**64 addresses: list(net) or list(net.hosts()) will hang the program and eat memory, so iterate lazily or work with in and subnets(). For IPv6, hosts() excludes only the first address (the Subnet-Router anycast address) and keeps the last one, since IPv6 has no broadcast. strict=True is the default, as for IPv4.
Examples
import ipaddress
net = ipaddress.IPv6Network('2001:db8::/64')
print(net.num_addresses == 2 ** 64) # → True
small = ipaddress.IPv6Network('2001:db8::/126')
print([str(h) for h in small.hosts()]) # → ['2001:db8::1', '2001:db8::2', '2001:db8::3']
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy