Skip to content

Instantly share code, notes, and snippets.

@wilhelm-murdoch
Last active October 22, 2021 13:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wilhelm-murdoch/3e6af107f378ada36e91601aedc636d1 to your computer and use it in GitHub Desktop.
Save wilhelm-murdoch/3e6af107f378ada36e91601aedc636d1 to your computer and use it in GitHub Desktop.
Ensure given VPC subnets have zero overlap.
#!/usr/bin/env python
import ipaddr
accounts = {
'flood-beta': {
'public': [
'10.1.32.0/20',
'10.1.96.0/20',
'10.1.160.0/20'
],
'private': [
'10.1.0.0/19',
'10.1.64.0/19',
'10.1.128.0/19'
],
'spare': [
'10.1.48.0/20',
'10.1.112.0/20',
'10.1.176.0/20'
]
},
'flood-prod': {
'public': [
'10.2.32.0/20',
'10.2.96.0/20',
'10.2.160.0/20'
],
'private': [
'10.2.0.0/19',
'10.2.64.0/19',
'10.2.128.0/19'
],
'spare': [
'10.2.48.0/20',
'10.2.112.0/20',
'10.2.176.0/20'
]
},
'flood-master': {
'public': [
'10.0.1.0/24',
'10.0.2.0/24',
'10.0.3.0/24'
],
'private': [
'10.0.0.0/24',
'10.0.4.0/24'
],
'spare': []
}
}
for account, blocks in accounts.iteritems():
print account
print '=========='
for block, cidrs in blocks.iteritems():
print block + ':'
overlapped = False
for cidr in cidrs:
n1 = ipaddr.IPNetwork(cidr)
print '===> ' + cidr
for account2, blocks2 in accounts.iteritems():
if account != account2:
for block2, cidrs2 in blocks2.iteritems():
for cidr2 in cidrs2:
n2 = ipaddr.IPNetwork(cidr2)
if n1.overlaps(n2):
overlapped = True
print '---> overlaps ' + cidr2 + ' in ' + account2
if not overlapped:
print 'all clear'
print
print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment