1

我在使用 socket.gethostbyaddr 返回 Windows 机器的 netbios 名称时遇到问题。在 Windows 上返回

Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:19:30) [MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.    
>>> import socket
>>> socket.gethostbyaddr("10.10.1.22")
('ZUNIT1', [], ['10.10.1.22'])
>>>

在我的 linux 机器上,我得到

Python 3.2.3 (default, Feb 27 2014, 21:31:18)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> socket.gethostbyaddr("10.10.1.22")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
socket.herror: [Errno 1] Unknown host
>>>

我已经在 linux 机器上安装了 winbind 并修改了 /etc/nsswitch.conf,所以我现在可以使用 netbios 名称来执行诸如使用 netbios 名称 ping 单元之类的事情。

alexm@malv:~$ ping ZUNIT1
PING ZUNIT1 (10.10.1.22) 56(84) bytes of data.
64 bytes from 10.10.1.22: icmp_req=1 ttl=128 time=0.461 ms
64 bytes from 10.10.1.22: icmp_req=2 ttl=128 time=0.371 ms
^C
--- ZUNIT1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1006ms
rtt min/avg/max/mdev = 0.371/0.416/0.461/0.045 ms
alexm@malv:~$

谁能告诉我我需要做什么才能让 Python 从 socket.gethostbyaddr 方法返回 netbios 名称?

编辑@user590028,gethostbyname 按预期工作。

Python 3.2.3 (default, Feb 27 2014, 21:31:18) 
[GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> socket.gethostbyname("ZUNIT1")
'10.10.1.22'
>>>
4

1 回答 1

0

问题是 linux 机器与我试图检索名称的机器具有不同的工作组。

于 2016-01-15T14:34:38.780 回答