使用paramiko.ProxyComand时找不到文件

时间:2014-02-05 16:36:10

标签: python-2.7 proxy paramiko

我的文件代码cpe_scan.py:

import Crypto
import paramiko
def runSshCmd(hostname, username, password, cmd, timeout=5):
    conf = paramiko.SSHConfig()
    conf.parse(open('/home/me/.ssh/config'))
    host = conf.lookup(hostname)
    print "Object host= ", host
    print "Object host.get= ", host.get('proxycommand')
    proxy = paramiko.ProxyCommand(host.get('proxycommand'))
    print "Object proxy= ", proxy

    client = paramiko.SSHClient()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    client.connect(hostname=hostname, username=username, password=password,
    allow_agent=False, look_for_keys=False, timeout=timeout, sock=proxy)

    stdin, stdout, stderr = client.exec_command(cmd)
    data = stdout.read()
    print data
    client.close()

runSshCmd("1.2.3.4", "user", "passwd", "ls -l")

结果是:

Object host=  {'hostname': '1.2.3.4', 'proxycommand': 'ssh me@myproxy nc 5.6.7.8 22'}
Object host.get=  ssh me@myproxy nc 5.6.7.8 22
Traceback (most recent call last):
File "cpe_scan.py", line 68, in <module>
    runSshCmd("1.2.3.4", "user", "passwd", "ls -l")
File "cpe_scan.py", line 48, in runSshCmd
    proxy = paramiko.ProxyCommand(host.get('proxycommand'))
File "build\bdist.win32\egg\paramiko\proxy.py", line 50, in __init__
File "C:\Python27\lib\subprocess.py", line 709, in __init__
    errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 957, in _execute_child
    startupinfo)
WindowsError: [Error 2] Impossibile trovare il file specificato

其中“Impossibile trovare il file specificato”等于“找不到指定的文件”英文

为什么呢?什么文件找不到?

我使用python 2.7.6,paramiko 1.12.1,pycrypto 2.6.1和ecdsa 0.10,我在windows xp上运行。

感谢

1 个答案:

答案 0 :(得分:0)

使用带有ssh的ProxyCommand时遇到了同样的错误。解决它的是指定ssh和nc二进制文件的完整路径(在我的例子中为/usr/bin/[ssh|nc])。你可以尝试一下,看看它是否解决了你的问题?我确定您知道这一点,但您可以使用which sshwhich nc找到可执行文件的路径。