-1
Python with netifacesは、ローカルホスト上でip、netmask情報を収集するのに最適ですが、リモートサーバから同じ情報を収集するのは非常に困難です。私はnetifacesがparamikoとサブプロセスやos.systemのようなリモートサーバを好まないと思う。Python - リモートLinuxホスト上のnetifacesモジュール
def interface_details():
for iface in netifaces.interfaces():
if iface == 'lo':
continue
iface_details = netifaces.ifaddresses(iface)
if iface_details.has_key(netifaces.AF_INET):
ipv4 = iface_details[netifaces.AF_INET]
return ipv4
そして、これは、それが失敗したかである:
# Using Paramiko to execute cmd.
>>> host_ssh.exec_command(interface_details())
File "build/bdist.linux-x86_64/egg/paramiko/client.py", line 441, in exec_command
File "build/bdist.linux-x86_64/egg/paramiko/channel.py", line 60, in _check
File "build/bdist.linux-x86_64/egg/paramiko/channel.py", line 231, in exec_command
File "build/bdist.linux-x86_64/egg/paramiko/message.py", line 285, in add_string
File "build/bdist.linux-x86_64/egg/paramiko/common.py", line 170, in asbytes
Exception: Unknown type
おかげ
また、ローカルのpythonスクリプトをssh経由でリモートのPythonにパイプすることもできます。 – pvg