Created
October 9, 2024 10:24
-
-
Save ungeskriptet/6b91bbbee854b26f4ae66005a5a8fd36 to your computer and use it in GitHub Desktop.
Python CIDR to IPv4 address converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import sys | |
cidr = sys.argv[1:][0] | |
octetts = ["0"] * 32 | |
ip_dec = [] | |
for i in range(int(cidr)): | |
octetts[i] = "1" | |
for a, b, c, d, e, f, g, h in zip(*[iter(octetts)]*8): | |
octett = a+b+c+d+e+f+g+h | |
ip_dec.append(str(int(octett, 2))) | |
print(".".join(ip_dec)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment