我正在尝试使用telnetlib使用我的python脚本远程登录到给定行上的cisco控制台服务器
下面我提到了我的代码:
import time
import getpass
import sys
import telnetlib
HOST = "172.30.144.182"
user = raw_input("enter the admin: ")
password = getpass.getpass()
tn = telnetlib.Telnet(HOST, "2035")
tn.read_until("E4Q16000001 login: ")
tn.write(user + '\n')
if password:
tn.read_until("Password: ")
tn.write(password + "\n")
tn.write("get system status\n")
print tn.read_very_eager()
mytext = tn.set_debuglevel(1000)
mytext = tn.read_all()
print mytext
tn.write("exit\n")
问题:在提供用户信息和密码后终端被挂起。 当我清除cisco终端上的线路时,我收到以下错误
Traceback (most recent call last):
File "./t1.py", line 15, in <module>tn.read_until("E4Q16000001 login: ")
File "/usr/lib/python2.7/telnetlib.py", line 294, in read_untilreturnself._read_until_with_poll(match, timeout)
File "/usr/lib/python2.7/telnetlib.py", line 343, in _read_until_with_pollreturn self.read_very_lazy()
File "/usr/lib/python2.7/telnetlib.py", line 455, in read_very_lazyraise EOFError, 'telnet connection closed'
我相信我的脚本正在连接控制台服务器(第35行的终端设备),因为当我清除cisco控制台服务器上的行时出现上述错误
方法: