Created
April 18, 2020 19:20
-
-
Save simonpainter/4c1771f6c6580164c0f46f0fb5368617 to your computer and use it in GitHub Desktop.
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
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