开发者

How to read only last buffer from telnetlib command

I have following python code:

import telnetlib
ts = telnetlib.Telnet('192.168.0.2')
ts.set_开发者_Go百科debuglevel(10)
ts.read_until("assword:", 5)
ts.write("xxxxx\n")
ts.write("enable\n")
ts.read_until("assword:", 5)
ts.write("xxxxx\n")
ts.write("term len 0\n")
ts.write("show start\n")

But how can i read the buffer only from "show start" command? If i try to read_(very)eager or read_all() I get all previous output too. Im confused because it looks like i should parse string on my own wrrr :( Maybe im wrong?


Try using ts.read_until("") before the command whose output you want to grab

import telnetlib  
ts = telnetlib.Telnet('192.168.0.2')  
ts.set_debuglevel(10) 
ts.read_until("assword:", 5)  
ts.write("xxxxx\n")  
ts.write("enable\n")  
ts.read_until("assword:", 5)  
ts.write("xxxxx\n")   
ts.read_until("")  #Add this line  
ts.write("term len 0\n")   
ts.write("show start\n")`
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜