1

I am trying to telnet into a cisco ios-xr router and gather command output.

I have tested that the below code successfully connects to the router and executes the command, however it seems that neither print tn.read_all() nor tn.read_very_eager() works. They do not print anything. Am I missing anything obvious here?

#!/usr/bin/env python
import sys
import telnetlib
import time 

HOST = "10.62.53.34"
PORT = "17006"
user = "cisco"
password = "cisco"

tn = telnetlib.Telnet(HOST,PORT)
print "Telnetting to", HOST, "@",PORT
tn.write("\n")
tn.write(user + "\n")
tn.write(password + "\n")
#print("I am in")
tn.write("show runn\n")
tn.write("exit \n")
print tn.read_all()
tn.close()
Matthew Murdoch
  • 30,874
  • 30
  • 96
  • 127
OzgurGuler
  • 11
  • 1
  • 3

1 Answers1

0

though this question is from february, i'll post my answer for a potential future googler.

i fixed a similar problem when i realized that:

print tn.read_all()

...is valid in python 2 (see the example at the bottom of https://docs.python.org/2/library/telnetlib.html), but not in python 3 (https://docs.python.org/3.6/library/telnetlib.html).

for python 3, the correct syntax would be:

print(tn.read_all())