小编abh*_*bhi的帖子

Python:Telnet 密码不是使用 pexpect 通过脚本获取的

我在使用 pexpect 运行我的 telnet 脚本时遇到问题。问题是它只从脚本中获取用户名而不是密码。它获取密码的值但它没有输入相同的值。在我的脚本下面提到,

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"
Run Code Online (Sandbox Code Playgroud)

这个的输出,

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
Run Code Online (Sandbox Code Playgroud)

python telnet pexpect

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

pexpect ×1

python ×1

telnet ×1