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)]) |