Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
from netaddr import IPNetwork, cidr_merge
import re, sys
try:
filename = sys.argv[1]
except:
print("Please specify a file name for input")
sys.exit()
with open (filename, "r") as file:
table = file.read().replace('\n', '')
prefixes = re.findall("(?:\d{1,3}\.){3}\d{1,3}\/\d+", table)
prefix_list = []
for each in prefixes:
prefix_list.append(IPNetwork(each))
summary_list = cidr_merge(prefix_list)
print('Number of prefixes ', len(prefix_list))
print('Number in summary ', len(summary_list))
print('Summary list:')
for each in summary_list:
print(each.cidr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.