Python, Pexpect操作telnet

艾派德迷你2 2015-07-03 03:45:01
用Python的Pexpect模块来操作
正常手动操作
1, telnet 10.1.1.2 2002
返回 Escape character is '^]'.
2.在下一行,输入? c1(这里看不见输入的字符)再回车,在当前这一行会有返回值
Escape character is '^]'.
56
3.再次输入,56会变成新的返回值

现在操作如下:
 try:
child.sendline("? c1")
tt = child.readline()
print(tt)
child.write("? c1\r")
tt1 = child.readline()
print(tt1)
child.expect('\r\n',timeout=5)
print("\r\n\r\n Tempurature: {temp} {temp1}".format(temp = child.before,temp1 = child.after))

except:
msg_show("Show temp fail due to time


但是运行结果是这样的
scape character is '^]'.
? c1
'^]'.

2015-07-03 15:47:32 Show temp fail due to timeout
...全文
436 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
艾派德迷你2 2015-07-06
  • 打赏
  • 举报
回复
自己搞定咯... 加咯1s延迟,并查看buffer,找到方法咯

37,743

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧