2016-02-18 63 views
1

我正在尝试telnet到Cisco IOS ios-xr路由器并收集命令输出。print tn.read_all()在telnetlib python脚本中不返回任何内容

我测试过,下面的代码成功连接到路由器并执行该命令,但似乎print tn.read_all()tn.read_very_eager()都不起作用。他们不打印任何东西。我在这里错过了什么?

#!/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() 

回答

相关问题