2013-05-02 84 views
2

我想從遠程登錄一臺Windows PC使用Python腳本(pexpect)。當我嘗試連接此錯誤彈出的操作成功完成...登錄失敗下面是我的python腳本。遠程登錄從Linux電腦到Windows PC使用Python腳本

import pexpect,time,sys 
from ftplib import FTP 
def tel(ipadrr,login,password): 

     try:  
       global telconn 
       telconn = pexpect.spawn(ipadrr) 
       telconn.logfile = open("/tmp/telnetlog", "a") 

       print "connected to telnet" 
       print 
     except: 
       print "telconnnet connection refused" 
       print 
       sys.exit() 

     try: 
       time.sleep(15) 
       #telconn.expect(": ") 
       print "username" 
       telconn.sendline(login + '\r') 
       telconn.expect(":") 
       print "password" 
       telconn.sendline(password + '\r') 
       #telconn.sendline("\r") 
       #time.sleep(30) 
       telconn.expect(">") 
       print "Authentication Sucesss" 
       print 
     except: 
       print "Authentication Failure" 
       print   
       sys.exit() 
+0

參數)應該是一個命令例如telnet 127.0.0.1。爲什麼不使用telnetlib模塊? – vszurma 2013-05-02 06:46:54

+0

請發佈一次運行的完整輸出。 @tecjam也正確地將完整的命令提供給.spawn()。 – Dave 2013-05-02 06:57:33

+0

Hi nolen 我已經在下面的程序中定義了def'tel'的值。 進口telnetftp,FTP,電話 進口Pexpect,第一次,從FTPLIB進口FTP telnetlib telnetftp.tel( 「遠程登錄192.0.0.105」, 「USR」, 「通過@ 123」。 我已經嘗試與telnetlib模塊但顯示相同的錯誤 – Vishnu 2013-05-02 07:01:50

回答

1

我想你的密碼不是通過腳本輸入的。嘗試用,

telconn.sendline(password + '\n') 
+0

@abhi ...我已經嘗試了這個,但結果是一樣的........ – Vishnu 2013-05-02 08:07:07

1

@ vish..its已經回答相同question..plz請驗證是否爲pexpect.spawn(同一

import pexpect 
import time,sys 
telconn = pexpect.spawn('telnet 192.168.0.105') 
time.sleep(20) 
telconn.logfile = sys.stdout 
telconn.expect(":") 
time.sleep(20) 
telconn.send("user" + "\r") 
telconn.expect(":") 
telconn.send("[email protected]" + "\r") 
telconn.send("\r\n") 
time.sleep(20) 
telconn.expect(">") 
相關問題