2 Inspecting Address/Network/Interface Objects You’ve gone to the trouble of creating an IPv(4|6)(Address|Network|Interface) object, so you probably want to get information about it. ipaddress tries to make doing this easy and intuitive. Extracting the IP version: Obtaining the network from an interface: Finding out how many individual addresses are in a network: Iterating through the “usable” addresses on a network: Obtaining the netmask (i.e. set bits corresponding to the network prefix) or the hostmask (any bits that are not part of the netmask): Exploding or compressing the address: 4 >>> addr4=ipaddress.ip_address('192.0.2.1 ') >>> addr6=ipaddress.ip_address('2001:db8::1 ') >>> addr6.version 6 >>> addr4.version 4 >>> host4 =ipaddress.ip_interface( '192.0.2.1/24 ') >>> host4.network IPv4Network('192.0.2.0/24') >>> host6 =ipaddress.ip_interface( '2001:db8::1/96 ') >>> host6.network IPv6Network('2001:db8::/96') >>> net4=ipaddress.ip_network( '192.0.2.0/24 ') >>> net4.num_addresses 256 >>> net6=ipaddress.ip_network( '2001:db8::0/96 ') >>> net6.num_addresses 4294967296 >>> net4=ipaddress.ip_network( '192.0.2.0/24 ') >>>for x in net4.hosts(): ... print(x) 192.0.2.1 192.0.2.2 192.0.2.3 192.0.2.4 ... 192.0.2.252 192.0.2.253 192.0.2.254 >>> net4=ipaddress.ip_network( '192.0.2.0/24 ') >>> net4.netmask IPv4Address('255.255.255.0') >>> net4.hostmask IPv4Address('0.0.0.255') >>> net6=ipaddress.ip_network( '2001:db8::0/96 ') >>> net6.netmask IPv6Address('ffff:ffff:ffff:ffff:ffff:ffff::') >>> net6.hostmask IPv6Address('::ffff:ffff')