2014-02-05 53 views
1

我有我的文件cpe_scan.py的這部分代碼:未找到文件,而使用paramiko.ProxyComand

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 [email protected] nc 5.6.7.8 22'} 
Object host.get= ssh [email protected] 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金正日文件specificato 「等於」找不到指定的文件「英文

爲什麼?什麼文件找不到?

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

感謝

回答

0

我使用ProxyCommand使用ssh擊中時同樣的錯誤。解決的辦法是指定ssh和nc二進制文件的完整路徑(我的情況爲/usr/bin/[ssh|nc])。你可以嘗試一下,看看它是否能解決你的問題?我相信你知道這一點,但你可以使用which sshwhich nc找到可執行文件的路徑。