Why does socket.inet_ntoa returns packed format in python
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 o开发者_高级运维r 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.
精彩评论