Show Commands

#ConnectHandler
from pprint import pprint
from netmiko import Netmiko
from getpass import getpass

password = getpass()

devices = {‘host’: ‘100.96.0.18’, ‘username’: ‘ntc’, ‘password’: ‘ntc123’, ‘device_type’: ‘cisco_xe’, ‘secret’: password}
net_conn = Netmiko(**devices)
net_conn.enable()

output = net_conn.send_command(“show arp”)
print(output)

with open(“show_arp.txt”, “w”) as f:
f.write(output)

Protocol Address Age (min) Hardware Addr Type Interface
Internet 100.96.0.2 12 5001.000d.0001 ARPA GigabitEthernet1
Internet 100.96.0.18 – 5001.0001.0000 ARPA GigabitEthernet1
Internet 100.96.0.22 206 5001.0003.0000 ARPA GigabitEthernet1

Send to Multiple devices :

#ConnectHandler
from pprint import pprint
from netmiko import Netmiko
from getpass import getpass

password = getpass()

csr1 = {‘host’: ‘100.96.0.18’, ‘username’: ‘ntc’, ‘password’: ‘ntc123’, ‘device_type’: ‘cisco_xe’, ‘secret’: password}
csr2 = {‘host’: ‘100.96.0.20’, ‘username’: ‘ntc’, ‘password’: ‘ntc123’, ‘device_type’: ‘cisco_xe’, ‘secret’: password}
csr3 = {‘host’: ‘100.96.0.22’, ‘username’: ‘ntc’, ‘password’: ‘ntc123’, ‘device_type’: ‘cisco_xe’, ‘secret’: password}

devices = [csr1, csr2, csr3]

for device in devices:
net_conn = Netmiko(**device)
net_conn.enable()

output = net_conn.send_command(“show arp”)
print(f”This is the arp table for {devices}”)  <—– wrong to be fix with something with device.keys() TBD
print(output)

Leave a Comment