python3 telnetlib返回结果非常慢

时间:2020-09-27 17:58:37

标签: python-3.x automation cisco gns3

我在gns3实验室中将telnet的确切python脚本写到了Cisco路由器和交换机中,它正在工作,但是至少需要10到20分钟才能在终端上显示结果,我的操作系统是Ubuntu 20.04,对于某些我既不想使用gns3自动化容器也不想使用python2的原因。(配置了TAP设备,我可以轻松ping和telnet到我的设备,因此手动配置没有问题),这里是脚本:

#!/usr/bin/env python3
import getpass
import telnetlib
HOST = "10.10.10.1"
user = input("Enter your username: ")
password = getpass.getpass()
tn = telnetlib.Telnet(HOST)tn.read_until(b"Username: ")
tn.write(user.encode('ascii') + b"\n")
if password:
    tn.read_until(b"Password: ")
    tn.write(password.encode('ascii') + b"\n")

tn.write(b"enable\n")
tn.write(b"conf t\n")

dev_info = tn.read_all().decode('ascii')

tn.close()

print(dev_info)

0 个答案:

没有答案