-1
Python與netifaces很適合在localhost上收集ip,netmask信息,但是我很難從遠程服務器收集相同的信息。我猜netifaces不喜歡paramiko以及遠程服務器上的子進程或os.system。遠程Linux主機上的Python - 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
感謝
您也可以通過ssh將本地python腳本通過管道連接到遠程python。 – pvg