The IP address objects

In the same way as with the network objects, you can check whether the address is private, reserved, or multicast.

In this example, the loopback interface is defined with the ::1 IP address. As you can see, the is_loopback property returns true:

 >>> loopback = ipaddress.IPv6Interface('::1')
>>> loopback.is_private
True
>>> loopback.is_reserved
True
>>> loopback.is_multicast
False
>>> loopback.is_loopback
True

The IP address classes have many more interesting properties. You can perform some arithmetic and logical operations on those objects. For example, we can check if an IP address is part of a network.

In this example, we check whether an IP is a part of a specific network. Here, a network net has been defined by the network address, which is 2001:db8:0:1::/64, and the membership of eth0 and eth1 has been checked for whether these interfaces are part of the network:

 >>> net6 = ipaddress.ip_network('2001:db8:0:1::/64')
>>> eth0 = ipaddress.IPv6Interface('2001:db8:0:1::beef')
>>> eth1 = ipaddress.IPv6Interface('2001:db7::/48')

>>> eth0 in net6
True
>>> eth1 in net6
False
>>>
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset