Last active
October 25, 2016 09:47
-
-
Save hedgeven/e8692238e2d6726fe1c3eb7912629a63 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
#!/usr/bin/env python3 | |
"""Generate aggregated network list from given file""" | |
import sys | |
from netaddr import IPSet, IPNetwork | |
def main(argv): | |
ipset = IPSet() | |
try: | |
with open(argv[1], 'r') as file_desc: | |
for line in file_desc.readlines(): | |
ipset.add(IPNetwork(line)) | |
except Exception as error: | |
print(error) | |
sys.exit(1) | |
aggr_networks = [str(n) for n in ipset.iter_cidrs()] | |
print('\n'.join(aggr_networks)) | |
if __name__ == "__main__": | |
main(sys.argv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment