【发布时间】:2017-10-28 21:43:54
【问题描述】:
我想在 python 中使用 pexpect lib 运行 telnet,如果 telnet 密码为真,则打印正确和错误,打印错误... 现在我的代码是:
import pexpect
ip="192.168.1.1"
password="admin"
child = pexpect.spawn("telnet "+ip+" -l admin", timeout=2)
child.expect ("Password:")
child.sendline ("admin")
child.expect(b"> ")
child.sendline ("ls")
child.close()
result = child.signalstatus
if result == 1:
print ("Success")
else:
print ("Bad Result")
在顶部代码中,当密码为真时,脚本运行良好并显示“成功”,但当密码错误时,脚本不显示“错误结果”,只是显示很多错误..
我该怎么做?
【问题讨论】: