为什么socket.inet_aton在python中返回打包格式?
如果我将 IP 作为整数存储在数据库 (mysql) 中,我是否必须始终提取整数值,或者是否有更简单的方法?
最佳答案
inet_aton明确记录了执行此任务的过程,并且“为什么”甚至得到了非常明确的解释......:
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.
要从 4 字节字符串转换为整数,反之亦然,请参阅 struct模块。
关于python - 为什么socket.inet_ntoa在python中返回打包格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2481413/