Skip to content

Instantly share code, notes, and snippets.

@Akendo
Created May 24, 2017 11:23
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Akendo/6cf70aa01f92ab2f03ae6c27480f713e to your computer and use it in GitHub Desktop.
Save Akendo/6cf70aa01f92ab2f03ae6c27480f713e to your computer and use it in GitHub Desktop.
Converting a netmask to CIDR with vanilla python
def netmask_to_cidr(m_netmask):
return(sum([ bin(int(bits)).count("1") for bits in m_netmask.split(".") ]))
@viniciusbuscacio
Copy link

Nice

@bfinnema
Copy link

Very useful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment