March 2019
Beginner
490 pages
12h 40m
English
Another use case is an IP subnetting application, which gives you the required IP subnets based on required network size or amount of networks per location. We can also find the subnet information from the IPv4Network objects, as follows:
>>> net4.subnets() <generator object _BaseNetwork.subnets at 0x02F2C0C0>>>> subnets = list( net4.subnets())>>> subnets [ IPv4Network('10.0.1.0/25'), IPv4Network('10.0.1.128/25') ]
The ipaddress module includes many functions to create subnets and supernets; for example, we can use these methods to check whether a network overlaps with another:
>>> ipnet = ipaddress.IPv4Network("10.2.0.0/16")>>> list(ipnet.subnets()) [IPv4Network('10.2.0.0/17'), IPv4Network('10.2.128.0/17')]
The subnets(prefixlen_diff=1, ...
Read now
Unlock full access