开发者

Why does socket.inet_ntoa returns packed format in python

开发者 https://www.devze.com 2022-12-23 07:00 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号