Python:Telnet 密码未使用 pexpect 通过脚本获取

标签 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"

这个的输出,

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

最佳答案

我有解决办法,

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("Pass@123" + "\r")
telconn.send("\r\n")
time.sleep(20)
telconn.expect(">")

这对我有用

关于Python:Telnet 密码未使用 pexpect 通过脚本获取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16396686/

相关文章:

python - tf.keras.metrics.AUC 是否适用于多类问题?

ios - 带身份验证的 Swift Telnet 流

python - 如何使用 Selenium Python xpath 单击某个按钮?

c# - 将 python 函数导入 .NET 语言?

Linux 脚本在一段时间内将 telnet 消息中的数据写入文件

windows - 能够打开 TCP 端口但不能监听

Python + Flask 网络应用报告 "[Errno 9] Bad file descriptor"与 pexpect 模块

python - 当匹配旧输出中的字符串时,pexpect python 模块的expect方法会中断

python - pytest-cov 如何报告由于 pexpect.spawn 而执行的 python 代码的覆盖率?

python - 带时区的时间戳,使用 django ORM 未知