Last active
March 20, 2017 08:15
-
-
Save dketov/7df9eceecc2154544a87b80ed048bd8a to your computer and use it in GitHub Desktop.
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
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