Windows マシンの netbios 名を返すために socket.gethostbyaddr を使用すると問題が発生します。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 名を使用してユニットに 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'
>>>