CIDR An acronym for Classless inter-domain routing. The meaning is "a mechanism that enables IP address assignment and route selection without using the concept of address class". (From the IT terminology dictionary that makes you feel "understood" even if you "understand" and "do not understand") https://wa3.i-3-i.info/word11990.html This site explains various IT terms. The description is very easy to understand even for amateurs, and it is useful.
netaddr A Python library used to operate IP networks. The official documentation (https://pypi.org/project/netaddr/) describes A network address manipulation library for Python. You can easily compare IP networks, take a set of differences, take an intersection, get a list of included IP addresses, and so on.
Use IPSet () to get the set of differences between IP blocks in CIDR notation.
>>> s1 = IPSet(['0.0.0.0/0']) # 0.0.0.0/Add 0 as an element
>>> s1.remove('255.255.255.255') # remove()Delete only the address specified in
>>> s1
IPSet(['0.0.0.0/1', '128.0.0.0/2', '192.0.0.0/3', '224.0.0.0/4', '240.0.0.0/5', ... '255.255.255.254/32'])
If you do this, the remaining IP blocks and addresses after deducting the address specified by remove will be returned in a list. Trying to do this without a library is quite annoying.
Recommended Posts