Skip to content

Instantly share code, notes, and snippets.

@skandix
Created September 4, 2020 07:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skandix/d2e5abbdb7d0fe5e8ff2f9a3c49ea2ce to your computer and use it in GitHub Desktop.
Save skandix/d2e5abbdb7d0fe5e8ff2f9a3c49ea2ce to your computer and use it in GitHub Desktop.
#!/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