March 2019
Beginner
490 pages
12h 40m
English
When working with an IP address that represents a network, we could work with an IPv4Network or IPv6Network object depending on the IP address passed as the argument. For this task, we can use the ip_network() method from the ipaddress module using as parameter a string or integer representing the IP network.
Let's import the ipaddress module and define a net6 network:
>>> import ipaddress >>> net6 = ipaddress.ip_network('2001:db8::/48')
Now, we get some useful information, such as version, netmask, and the network/broadcast address:
>>> net6.version 6>>> net6.netmask IPv6Address('ffff:ffff:ffff::')
Similarly, you can find the network and the broadcast addresses of net6 by doing the following:
>>> net6.network_address ...
Read now
Unlock full access