Created
September 4, 2020 07:38
-
-
Save skandix/d2e5abbdb7d0fe5e8ff2f9a3c49ea2ce 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
#!/usr/bin/env python | |
_input = "10.0.0.0/32" | |
def cidr_hosts_calc(n): | |
return 2**(32-n) | |
cidr_mask = int(_input.split('/')[-1]) | |
if int(cidr_mask) < 0: | |
print('Mask can\'t be less than 0') | |
quit() # Ghetto break | |
elif int(cidr_mask) > 32: | |
print('Mask can\'t be larger than 32') | |
quit() # Ghetto break | |
_ip = _input.split('/')[0].split('.') | |
hosts = cidr_hosts_calc(cidr_mask) | |
print(hosts) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment