Skip to content

Instantly share code, notes, and snippets.

@teepark
Forked from joshourisman/gist:204279
Created October 15, 2009 05:33
Show Gist options
  • Save teepark/210708 to your computer and use it in GitHub Desktop.
Save teepark/210708 to your computer and use it in GitHub Desktop.
from struct import pack, unpack
def encode(ip_address):
return unpack('i', ''.join([pack('B', int(sub)) for sub in ip_address.split('.')]))[0]
def decode(packed_address):
return '.'.join(['%d' % unpack('B', sub)[0] for sub in pack('i', packed_address)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment