亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 python (netmiko) 中從循環中獲取多個輸出到外部

如何在 python (netmiko) 中從循環中獲取多個輸出到外部

互換的青春 2023-05-23 10:47:42
我是蟒蛇的新手。我有使用 netmiko 在多個交換機上運行多個“顯示命令”的代碼,當一切都在循環中時它工作正常。但是當我想通過將其分配為變量并打印它來將多個“顯示命令”的輸出帶到循環外時,只打印輸出之一。S1 = {    'device_type': 'cisco_ios',    'ip': '192.168.0.56',    'username': 'admin',    'password': 'admin'    }S2= {    'device_type': 'cisco_ios',    'ip': '192.168.0.57',    'username': 'admin',    'password': 'admin'    }all_devices = [S1,S2]for devices in all_devices:    print("\nLogging into the switch...")    net_connect = ConnectHandler(**devices)    net_connect.enable()    cmd = ["show vlan brief", "\n","\n","show ip interface brief"]    for show in cmd:        output=net_connect.send_command(show)        y = outputprint(y)
查看完整描述

1 回答

?
喵喔喔

TA貢獻1735條經驗 獲得超5個贊

嘗試這個:


S1 = {

    'device_type': 'cisco_ios',

    'ip': '192.168.0.56',

    'username': 'admin',

    'password': 'admin'

    }


S2= {

    'device_type': 'cisco_ios',

    'ip': '192.168.0.57',

    'username': 'admin',

    'password': 'admin'

    }


all_devices = [S1,S2]


y = []


for devices in all_devices:

    print("\nLogging into the switch...")

    net_connect = ConnectHandler(**devices)

    net_connect.enable()

    cmd = ["show vlan brief", "\n","\n","show ip interface brief"]

    for show in cmd:

        output=net_connect.send_command(show)

        y.append(output)


for x in y:

    print(x)


查看完整回答
反對 回復 2023-05-23
  • 1 回答
  • 0 關注
  • 131 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號