Created
July 24, 2015 15:19
-
-
Save thepacketgeek/1fe3b4522dccfe377599 to your computer and use it in GitHub Desktop.
Convert Subnet Mask to CIDR length
This file contains 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 calc_mask_length(mask): | |
""" Convert subnet mask (255.255.255.0) to CIDR mask length (/24) """ | |
return sum([bin(int(x)).count('1') for x in mask.split('.')]) | |
print calc_mask_length('255.255.255.0') | |
# 24 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment