Last active
June 23, 2020 17:37
-
-
Save raspi/c61b6e8a8163bd840acdf8dfbdc76bee to your computer and use it in GitHub Desktop.
IP Address range to CIDR
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/env python3 | |
# IP address range to CIDR | |
import sys | |
import ipaddress | |
if (len(sys.argv) - 1) != 2: | |
print("Usage: ") | |
print(f" {sys.argv[0]} <ip address> <ip address>") | |
print("Example: ") | |
print(f" {sys.argv[0]} 192.168.0.0 192.168.0.255") | |
sys.exit(0) | |
ip1 = ipaddress.ip_address(sys.argv[1]) | |
ip2 = ipaddress.ip_address(sys.argv[2]) | |
for i in ipaddress.summarize_address_range(ip1, ip2): | |
print(i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment