Created
April 8, 2020 13:31
-
-
Save BookGin/54a555fd0979b52c4e4643ab994e2270 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
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