Skip to content

Instantly share code, notes, and snippets.

@marianmirzacu
Created April 13, 2021 19:31
Show Gist options
  • Save marianmirzacu/484bb76f04c9060a359078731300c40f to your computer and use it in GitHub Desktop.
Save marianmirzacu/484bb76f04c9060a359078731300c40f to your computer and use it in GitHub Desktop.
from ipaddress import ip_network
start = '0.0.0.0/0'
exclude = ['192.168.1.0/24']
result = [ip_network(start)]
for x in exclude:
n = ip_network(x)
new = []
for y in result:
if y.overlaps(n):
new.extend(y.address_exclude(n))
else:
new.append(y)
result = new
print(','.join(str(x) for x in sorted(result)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment