I'm using Python's telnetlib to telnet to network router and executing few commands and I want to get the output of these commands.
tn = telnetlib . Telnet ( "x.x.x.x", 23, 600 )
tn.expect([b"login as:"], 5)
tn.write(b'admin\r')
tn.expect([b"Password:"], 5)
tn.write(b"abc\r")
tn.write(b"show version\r")
time.sleep(3)
ret1 = tn.read_eager().decode('ascii')
print("Show Version Start \n")
print(repr(ret1))
print("\nShow Version End")
tn.write(b"exit\r")
print(tn.read_all().decode('ascii'))
tn.close()
I only want output of show version but its showing all output, is there way to only get output of last command executed??