一个脚本中存在多个 cisco 交换机的问题

问题描述 投票:0回答:1

我有一个脚本,可以从文件中读取IP地址,然后它正确地远程登录到专为远程登录到其他交换机而设计的路由器,其他交换机没有对外部网络的网络访问权限。

仅配置了第一个交换机,但环路的输出表明所有 IP 均已检查

我可以在控制路由器中看到,只有第一个交换机连接到已配置的交换机,即使代码中的打印表明环路中的所有 IP 都已连接。

import telnetlib

host ="1.1.1.1"
tn=telnetlib.Telnet(host) #TELNET TO CONTROL ROUTER
tn.write(b"\n")
tn.read_until(b"#")

file = open ('myswitches') # FILE HAS IPS OF SWITCHES

for IP in file:
    tn.write(b"telnet " + IP.encode('ascii') + "\n".encode('ascii'))
    print("CONFIGURING SWITCH " + (IP)) #OUTPUT IS SEEN FOR ALL SWITCHES IN LOOP
    tn.write(b"\n")
    tn.write(b"cisco\n")
    tn.write(b"cisco\n")
    tn.write(b"configure terminal\n")
    tn.write(b"VLAN 88\n")
    tn.write(b"NAME PYTHON_VLAN88\n")
    tn.write(b"end\n")
    tn.write(b"\n")
    tn.write(b"\n")
    tn.write(b"quit\n")

print("END OF SCRIPT")
python automation cisco
1个回答
0
投票

在评论中,您说:

脚本运行速度似乎太快,控制路由器无法应用配置。

只需在所有命令之间添加

time.sleep(0.5)

© www.soinside.com 2019 - 2024. All rights reserved.