netutils
netutils copied to clipboard
Add is_classful IP function
Environment
- netutils version: 1.2.0
Proposed Functionality
Add a function to return if an ip/CIDR is classful or not.
Use Case
Could be useful in Cisco IOS BGP statements. (It was also mentioned on public slack.)
Jeffs initial janky attempt. (Jeff said janky...not me!)
>>> classful = {8: range(0,128), 16: range(128, 192), 24: range(192, 224)}
>>> i = ipaddress.ip_network("192.168.1.0/24")
>>> if int(str(i).split(".")[0]) in classful[i.prefixlen]:
... print("Classful")
... else:
... print("Not Classful")
...
Classful
>>>
>>> i = ipaddress.ip_network("12.168.1.0/24")
>>> if int(str(i).split(".")[0]) in classful[i.prefixlen]:
... print("Classful")
... else:
... print("Not Classful")
...
Not Classful