Skip to content

Instantly share code, notes, and snippets.

@goncalor
Last active January 8, 2021 22:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goncalor/0b52ae8e9deb380c7fec73493d80918f to your computer and use it in GitHub Desktop.
Save goncalor/0b52ae8e9deb380c7fec73493d80918f to your computer and use it in GitHub Desktop.
#!/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