Network interface objects

In the ipaddress module, a convenient class is used to represent an interface's IP configuration in detail. The IPv6 interface class lets you extract the IPv6Address and IPv6Network objects from a single instance:

>>> eth0 = ipaddress.IPv6Interface('2001:db8::/48')
>>> eth0.ip
IPv6Address('2001:db8::')
>>> eth0.with_prefixlen
'2001:db8::/48'
>>> eth0.with_netmask
'2001:db8::/ffff:ffff:ffff::'
>>> eth0.network
IPv6Network('2001:db8::/48')
>>> eth0.is_private
True
>>> eth0.is_reserved
False
>>> eth0.is_multicast
False
>>> eth0.is_link_local
False
>>> eth0.is_global
False

As you can see, a network interface, eth0, with the IPv6Address class has been defined. It has some interesting properties, such as IP and network address. In the same way as with the network objects, you can check whether the address is private, reserved, multicast, link_local, or global.

Also, we can work with the ip_interface method to extract the IP address and network:

>>> intf = ipaddress.ip_interface("2001:db8::/48")
>>> intf.ip
IPv6Address('2001:db8::')
>>> intf.network
IPv6Network('2001:db8::/48')
..................Content has been hidden....................

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