Why does socket.inet_aton returns packed format in python?
If I am storing the IP as integer in Database (mysql), do I have to always extract the integer value or is there any easier way out?
Why does socket.inet_aton returns packed format in python?
If I am storing the IP as integer in Database (mysql), do I have to always extract the integer value or is there any easier way out?
inet_aton is clearly documented to perform exactly this task, and the "why" is even very explicitly explained...:
Convert an IPv4 address from dotted-quad string format (for example, ‘123.45.67.89’) to 32-bit packed binary format, as a string four characters in length. This is useful when conversing with a program that uses the standard C library and needs objects of type struct
in_addr
, which is the C type for the 32-bit packed binary this function returns.
To convert from a 4-byte string to an integer and vice versa, see the struct module.