Last active
January 8, 2021 22:51
-
-
Save goncalor/0b52ae8e9deb380c7fec73493d80918f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
import sys | |
import ipaddress | |
if len(sys.argv) != 2: | |
print("Usage: {} <file>".format(sys.argv[0])) | |
sys.exit(-1) | |
with open(sys.argv[1]) as f: | |
for line in f.readlines(): | |
line = line.strip() | |
if not '-' in line: | |
print(line) | |
else: | |
(ip1, ip2) = line.split('-') | |
for net in list( | |
ipaddress.summarize_address_range( | |
ipaddress.IPv4Address(ip1), | |
ipaddress.IPv4Address(ip2))): | |
print(net) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment