Skip to content

Instantly share code, notes, and snippets.

@lanbugs
Created May 12, 2023 17:58
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 lanbugs/937190c5efa87260ad8d94da0c35eb7f to your computer and use it in GitHub Desktop.
Save lanbugs/937190c5efa87260ad8d94da0c35eb7f to your computer and use it in GitHub Desktop.
Compress list of subnets and ips
import sys
from netaddr import cidr_merge
def main(FILE):
with open(FILE) as f:
raw_lines = f.readlines()
subnets = []
for line in raw_lines:
subnets.append(line.strip())
subnets = cidr_merge(subnets)
for subnet in subnets:
print(subnet)
if __name__ == "__main__":
main(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment