Netmiko : 连接到路由器,参数无效 ^

问题描述

我试图连接到路由器,只是为了得到一个命令的结果,代码如下:

from netmiko import ConnectHandler 

router = { "device_type": "xxxx","host": "xxxx","username": "xxxx","password": "xxxx",} 

command = "show arp all" 

net_connect= ConnectHandler(**router)
output = net_connect.send_command(command) 

print(output)

我收到这个错误'错误:参数无效^'我不明白问题出在哪里!

有人能找出错误吗!

解决方法

我认为错误在于命令本身。命令中没有 all。请考虑在没有 show arp 的情况下发送 show ip arpall。看看这个link。您还可以将 "session_log": "router.log" 添加到路由器的字典中,并在 router.log 文件中查找无效参数消息。

日志文件显示设备上 CLI 中发生的情况。

尝试执行以下操作:

router = {
    "device_type": "xxxx","host": "xxxx","username": "xxxx","password": "xxxx","session_log": "router.log"  # <--- this line
}

cmd = "show arp"  # or "show ip arp"

net_connect = ConnectHandler(**router)
arp_output = net_connect.send_command(cmd)
net_connect.disconnect() # to clear the vty line when done

print(arp_output)