【问题标题】:Python:Telnet password is not taking via script using pexpectPython:Telnet 密码未通过使用 pexpect 的脚本获取
【发布时间】:2013-04-30 02:05:06
【问题描述】:

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

【问题讨论】:

    标签: python telnet pexpect


    【解决方案1】:

    我找到了解决方案,

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

    这对我有用

    【讨论】:

    • telconn.send("\r\n") 的用途是什么?
    猜你喜欢
    • 2020-08-11
    • 2017-11-19
    • 2015-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-17
    • 2019-10-15
    • 2021-04-23
    相关资源
    最近更新 更多