【发布时间】:2020-03-27 23:21:03
【问题描述】:
谁能帮助我,我是编程初学者,我的问题是输出我只想过滤mac地址。我该怎么做。
from netmiko import ConnectHandler
cisco = {
'device_type' : 'cisco_ios',
'host' : '192.168.X.Y',
'username' : 'foo',
'password' : '123',
}
net_connect = ConnectHandler(**cisco)
net_connect.find_prompt()
show_mac = net_connect.send_command("show mac address-table vlan 100")
print(show_mac)
输出:
Vlan Mac Address Type Ports
---- ----------- -------- -----
100 264b.edf4.eba2 DYNAMIC Gi0/3
100 2680.f1ee.c0b1 DYNAMIC Gi0/2
100 3a60.2954.1ee2 DYNAMIC Gi1/3
100 4a60.05bd.27fc DYNAMIC Gi1/2
100 7e02.eee8.0291 DYNAMIC Gi0/1
100 b689.d44e.afd1 DYNAMIC Gi1/0
100 d207.6258.5966 DYNAMIC Gi1/1
Total Mac Addresses for this criterion: 7
【问题讨论】:
-
过滤器是什么意思?你的意思是只打印mac地址与指定列表匹配的行吗?
-
你能在打印时显示输出吗(type(show_mac))
-
您可以检查 send_command 中的 'expect_string' 和 'changeto' 参数以获得帮助,也可以使用 help(net_connect.send_command)