Created
October 7, 2009 18:14
-
-
Save joshourisman/204279 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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