/ Published in: Python
Convert an IP address to an integer for easier storage.
Also, convert an integer back to an IP address.
Also, convert an integer back to an IP address.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
def IntToDottedIP( intip ): octet = '' for exp in [3,2,1,0]: octet = octet + str(intip / ( 256 ** exp )) + "." intip = intip % ( 256 ** exp ) return(octet.rstrip('.')) def DottedIPToInt( dotted_ip ): exp = 3 intip = 0 for quad in dotted_ip.split('.'): intip = intip + (int(quad) * (256 ** exp)) exp = exp - 1 return(intip)