套接字.gethostbyaddr()在linux中返回空别名列表,但在windows中不返回

2024-05-21 02:03:31 发布

您现在位置:Python中文网/ 问答频道 /正文

Python的套接字.gethostbyaddr()在linux上返回空别名列表

我在Windows和Linux上都试过Python2和Python3。当然,它可以在windows下工作,但不能在Linux(Ubuntu和RedHat)上使用相同的IP来解析。我也在这两个系统上做了wireshark捕获,我们清楚地看到了包含所有别名的DNS答案。你知道吗

import socket
print(socket.gethostbyaddr('192.168.11.1'))

在windows上,我得到的答案是这样的:

('test123.com', ['alias1.test123.com', 'alias2.test123.com'], ['192.168.11.1'])

在linux上,我得到:

('alias1.test123.com', [], ['192.168.11.1'])

有人知道解决办法吗?你知道吗


Tags: 答案com列表ubuntulinuxwindowssocketpython3