Skip to content

Instantly share code, notes, and snippets.

@eiginn
Created March 28, 2016 21:25
Show Gist options
  • Save eiginn/3285baf647fd1403ce18 to your computer and use it in GitHub Desktop.
Save eiginn/3285baf647fd1403ce18 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# GistID: 3285baf647fd1403ce18
import sys
from netaddr import IPNetwork, cidr_merge, AddrFormatError
CF_ANYCAST_NETS = []
lines = []
if len(sys.argv) > 1:
with open(sys.argv[1]) as f:
for line in f.readlines():
lines.append(line)
else:
for line in sys.stdin.readlines():
lines.append(line)
for line in lines:
try:
CF_ANYCAST_NETS.append(IPNetwork(line))
except AddrFormatError:
pass
for net in cidr_merge(CF_ANYCAST_NETS):
print net
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment