Skip to content

Instantly share code, notes, and snippets.

@joshourisman
Created October 7, 2009 18:14
Show Gist options
  • Save joshourisman/204279 to your computer and use it in GitHub Desktop.
Save joshourisman/204279 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