我在运行telnet脚本时遇到问题,使用pexpect。问题是它只从脚本中获取用户名而没有密码。它获取了密码的值,但却没有输入相同的值。下面是我的脚本:
import pexpect
import sys,time
ipaddr = "192.168.100.85"
username = "usr"
password = "Pass@123"
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: Pass@123
The operation completed successfully.
Login Failed
telconn.send("\r\n")
的作用是什么? - L. Don