Created
March 7, 2013 16:53
-
-
Save avargas/5109610 to your computer and use it in GitHub Desktop.
returns an array of start and end ip ranges in int
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 cidr_range(cidr): | |
ip, subnet = cidr.split('/') | |
ipint = ip2int(ip) | |
subnet = int(subnet) | |
mask = ''.join(['1' for num in range(subnet)] + ['0' for num in range(32 - subnet)]) | |
inverted_mask = ''.join(['0' for num in range(subnet)] + ['1' for num in range(32 - subnet)]) | |
mask_int = int(mask, 2) | |
inverted_mask_int = int(inverted_mask, 2) | |
network = ipint & mask_int | |
return (network, network | inverted_mask_int) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment