2013-05-06 15 views
3

我有一個問題,而運行我的telnet腳本使用pexpect.problem是它只取用戶名從腳本不password.Its採取的密碼的價值,但它不輸入相同。下面提到我的劇本,Python:telnet密碼不是通過腳本使用pexpect

import pexpect 
import sys,time 
ipaddr = "192.168.100.85" 
username = "usr" 
password = "[email protected]" 
telconn = pexpect.spawn("telnet " + ipaddr) 
telconn.expect(":") 
telconn.logfile=sys.stdout 
time.sleep(15) 
telconn.sendline(username + "\r") 
telconn.expect(":") 
telconn.sendline(password + "\r") 
time.sleep(30) 
telconn.expect(">") 
print "Authentication Sucesss" 

輸出的這一點,

Trying 192.168.100.85... 
Connected to 192.168.100.85. 
Escape character is '^]'. 
Welcome to Microsoft Telnet Service 


login: usr 

password: [email protected] 

The operation completed successfully. 

Login Failed 

回答

3

我得到了這個解決方案,

import pexpect 
import time,sys 
telconn = pexpect.spawn('telnet 192.168.100.85') 
time.sleep(20) 
telconn.logfile = sys.stdout 
telconn.expect(":") 
time.sleep(20) 
telconn.send("usr" + "\r") 
telconn.expect(":") 
telconn.send("[email protected]" + "\r") 
telconn.send("\r\n") 
time.sleep(20) 
telconn.expect(">") 

這對我有效

+0

+1這也適用於我。感謝abhi。 – 2014-04-16 20:20:05