python - 为什么socket.inet_ntoa在python中返回打包格式

标签 python ip-address

为什么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/

相关文章:

Python 在多列中查找重复项

Python:变量、继承和默认参数

找不到 Python Office 365 Rest API 模块

在内核模块中将网络字节序IP转换为ip4格式的主机字节序

c# - 获取wifi连接系统的IP地址

python 列出 bin 大小的平均值

python - jinja2 django 模板中的 pgettext

php - 无法从托管在 GODADDY 上的站点获取机器的本地 IP 地址

amazon-web-services - 亚马逊如何拥有弹性 IP 的专有权

c++ - 使用保存的客户端 ip 地址将数据包从服务器发送到特定客户端?