Created
April 9, 2021 16:19
-
-
Save DDuarte/94aa88c835a2e2739ecea35f215a3a92 to your computer and use it in GitHub Desktop.
IPv4 public subnets excluding RFC 1918
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
from ipaddress import ip_network | |
rfc_1918 = [ip_network('10.0.0.0/8'), ip_network('172.16.0.0/12'), ip_network('192.168.0.0/16')] | |
final = [ip_network('0.0.0.0/0')] | |
for ex in rfc_1918: | |
for n in list(final): | |
try: | |
final.extend(n.address_exclude(ex)) | |
final.remove(n) | |
except ValueError as ex: | |
pass | |
# 0.0.0.0/5 | |
# 8.0.0.0/7 | |
# 11.0.0.0/8 | |
# 12.0.0.0/6 | |
# 16.0.0.0/4 | |
# 32.0.0.0/3 | |
# 64.0.0.0/2 | |
# 128.0.0.0/3 | |
# 160.0.0.0/5 | |
# 168.0.0.0/6 | |
# 172.0.0.0/12 | |
# 172.128.0.0/9 | |
# 172.32.0.0/11 | |
# 172.64.0.0/10 | |
# 173.0.0.0/8 | |
# 174.0.0.0/7 | |
# 176.0.0.0/4 | |
# 192.0.0.0/9 | |
# 192.128.0.0/11 | |
# 192.160.0.0/13 | |
# 192.169.0.0/16 | |
# 192.170.0.0/15 | |
# 192.172.0.0/14 | |
# 192.176.0.0/12 | |
# 192.192.0.0/10 | |
# 193.0.0.0/8 | |
# 194.0.0.0/7 | |
# 196.0.0.0/6 | |
# 200.0.0.0/5 | |
# 208.0.0.0/4 | |
# 224.0.0.0/3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment