Skip to content

Instantly share code, notes, and snippets.

@apackeer
Created October 3, 2012 06:49
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 apackeer/3825451 to your computer and use it in GitHub Desktop.
Save apackeer/3825451 to your computer and use it in GitHub Desktop.
Convert CIDR mask to dotted decimal
from socket import inet_ntoa
from struct import pack
bits = 0
mask = 25
for i in xrange(32 - mask,32):
bits |= (1 << i)
dotted_decimal = inet_ntoa(pack('>I', bits))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment