Skip to content

Instantly share code, notes, and snippets.

@richardstrnad
Created August 28, 2015 18:02
Show Gist options
  • Save richardstrnad/541ee0249f38b07f4d22 to your computer and use it in GitHub Desktop.
Save richardstrnad/541ee0249f38b07f4d22 to your computer and use it in GitHub Desktop.
def get_mask(ip1, ip2):
mask = []
ip1_split = ip1.split('.')
ip1_split[-1] = str(int(ip1_split[-1]) - 1)
ip2_split = ip2.split('.')
ip2_split[-1] = str(int(ip2_split[-1]) + 1)
for i, j in zip(ip1_split, ip2_split):
mask.append(str(255 - (int(j) - int(i))))
return '.'.join(mask)
test_list = [
['10.10.10.1', '10.10.10.254'],
['10.10.10.17', '10.10.10.30'],
['10.10.0.1', '10.10.3.254'],
['10.240.0.1', '10.243.255.254']
]
for ip1, ip2 in test_list:
get_mask(ip1, ip2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment