I am wondering how to create a script that takes a cidr notation like this:
204.15.20.0/22
And calculates all possible IP addresses in that range.
204.15.20.0
...
...
204.15.23.255
Now I finally know the math behind this, I was wondering how I could make such a module in python.
I am aware of ready-available modules such as netaddr.IPNetwork() but I am wondering how I would do this, using only the built-in modules in Python 2.7
Thanks :)
You can convert between IPv4 addresses and integers with a combination of the
socket
andstruct
modules. After that its a question of masking the integer address and figuring out the range of values in the subnet from the cidr value.