We sometimes swap an integer with an IP address, and the Python code makes it simple.
Converts an integer, such as 2000000, into an IP address
Import Socket Import struct>>> int_ip = 123456789>>> ip = Socket.inet_ntoa (struct.pack ('I ', socket.htonl (int_ip)) #int to IP address'7.91.205.21 '>>> Socket.ntohl (Struct.unpack ("I", Socket.inet_aton (str (IP))) [ 0]) #IP address to int123456789L
Actually this is the conversion of the binary number, we can write our own code
# Integer to IP address format
def ch1 (num): = [] for in Range ( 4): %256)/= return '. '. Join (s[::-1])>>> ch1 (123456789)'7.91.205.21 '
In a lambda way, integer TOIP address a line of code to fix
Lambda ' . ' for in range (3,-1,-1)])>>> CH2 (123456789)'7.91.205.21'
In lambda mode, IP addresses are converted to integers
Lambda for in Enumerate (X.split ('. ') [:: -1]]) >>> CH3 ('7.91.205.21')123456789