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

2024-04-28 22:31:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我在使用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

Tags: import脚本密码timeusrsysusernamesleep
1条回答
网友
1楼 · 发布于 2024-04-28 22:31:21

我有办法解决这个问题

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(">")

这对我有效

相关问题 更多 >