Network interface objects

In the ipaddress module, we have a convenient class to represent an interface's IP configuration in detail: IPv4Interface. It takes an arbitrary address and behaves like a network address object:

>>> import ipaddress
>>> eth0 = ipaddress.IPv4Interface('192.168.0.1/24')
>>> eth0.ip
IPv4Address('192.168.0.1')
>>> eth0.with_prefixlen
'192.168.0.1/24'
>>> eth0.with_netmask
'192.168.0.1/255.255.255.0'
>>> eth0.network
IPv4Network('192.168.0.0/24')
>>> eth0.is_private
True
>>> eth0.is_reserved
False
>>> eth0.is_multicast
False
>>>

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

..................Content has been hidden....................

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