我一直在做一些網路自動化,現在我正在與 lops 一起作業,以便能夠一次只做一個,所以當我運行下面的代碼時,我看到第一個路由器是成功的,但第二個路由器有錯誤 netmiko。 ssh_exception.NetmikoTimeoutException:讀取通道超時,資料不可用。
所以我正在測驗 3 個路由器,第一個運行良好,但第二個無法正常作業。
from netmiko import Netmiko
from getpass import getpass
import re
router1 = {
"host": "10.0.0.248",
"username": "cisco",
"password": "cisco",
"device_type": "cisco_ios",
}
router2 = {
"host": "10.0.0.247",
"username": "cisco",
"password": "cisco",
"device_type": "cisco_ios",
}
router3 = {
"host": "10.0.0.246",
"username": "cisco",
"password": "cisco",
"device_type": "cisco_ios",
}
routers = [router1, router2, router3]
interface_shut = list()
for router in routers:
net_connect = Netmiko(**router)
print(net_connect.find_prompt())
output = net_connect.send_command("show ip int br")
print(output)
find_interfaces = re.findall("GigabitEthernet\d.\d", output)
print(find_interfaces)
for int in find_interfaces:
interface_shut.append("Interface " int)
interface_shut.append("no shut")
output2 = net_connect.send_config_set(interface_shut)
print(output2)
interface_shut = list() # I am doing this so the list doesnt have to have more than 3 items for each device
print(interface_shut)
net_connect.disconnect()
uj5u.com熱心網友回復:
那是我的錯。代碼作業正常。我只是忘了在其他 2 個路由器中添加 priv 15。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/436064.html
標籤:python-3.x for循环 网络编程 网美子
上一篇:如何使用slim將div嵌套在for回圈中的另一個div中
下一篇:為什么3不是質數?
