netutils icon indicating copy to clipboard operation
netutils copied to clipboard

Add is_classful IP function

Open qduk opened this issue 2 years ago • 1 comments

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.)

qduk avatar Oct 19 '22 14:10 qduk

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

qduk avatar Oct 19 '22 14:10 qduk