python telnet线程锁_Python:Telnet密码未通过使用pexpect的脚本获取

我在使用pexpect运行telnet脚本时遇到问题.问题是它仅从脚本中获取用户名而不是从密码中获取.它使用password的值但未输入相同的值.

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

这对我有用

标签:pexpect,telnet,python

来源: https://codeday.me/bug/20191123/2066851.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值