Skip to content

Instantly share code, notes, and snippets.

@BookGin
Created April 8, 2020 13:31
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 BookGin/54a555fd0979b52c4e4643ab994e2270 to your computer and use it in GitHub Desktop.
Save BookGin/54a555fd0979b52c4e4643ab994e2270 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import ipaddress
ips = [ipaddress.ip_network('0.0.0.0/0')]
exts = map(ipaddress.ip_network,·
'''
10.0.0.0/8
172.16.0.0/12
192.168.0.0/16
127.0.0.0/8
'''.strip().splitlines())
def negate(ips, negate_ip):
new_ips = []
for ip in ips:
new_ips += list(ip.address_exclude(negate_ip)) if ip.overlaps(ext) else [ip]
return new_ips
for ext in exts:
ips = negate(ips, ext)
for ip in ips:
print(ip)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment