1

I have following python code:

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.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?

kamoks
  • 85
  • 2
  • 7
  • Please clarify your question. what do you mean by "the buffer only from `show start`"? you sent that bit of string. In any case, I don't know of a way to make telnetLib flush its buffers without returning them to you – Yoni H Aug 12 '10 at 14:17
  • In this case can't you just `read_all()` and strip off the first five or so lines? – Katriel Aug 12 '10 at 15:13

1 Answers1

4

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")`
Mariusz Jamro
  • 30,615
  • 24
  • 120
  • 162
ssegga
  • 41
  • 2