How do I convert a IPv4 subnet mask to CIDR range? I have subnet and gateway information available.
Data available:
- Subnet Mask: 255.255.255.0
- Gateway: 192.0.2.250
- Expected CIDR notation: 192.0.2.0/24
I know using ipaddress, CIDR value can be obtained.
from ipaddress import IPv4Network
ip4 = IPv4Network('0/255.255.255.0')
print(ip4.prefixlen)
print(ip4.with_prefixlen)
with results
24
0.0.0.0/24