Skip to content

Instantly share code, notes, and snippets.

@dketov
Last active March 20, 2017 08:15
Show Gist options
  • Save dketov/7df9eceecc2154544a87b80ed048bd8a to your computer and use it in GitHub Desktop.
Save dketov/7df9eceecc2154544a87b80ed048bd8a to your computer and use it in GitHub Desktop.
def str_to_mask(mask):
return reduce(lambda x, y: y+(x<<8), map(int, mask.split(".")), 0)
def check_ip_mask(mask):
while mask & 0x7fffffff:
if not mask & 0x40000000:
return False
mask <<= 1
return True
mask = '255.255.193.0'
print bin(str_to_mask(mask))
print check_ip_mask(str_to_mask(mask))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment