BASIC PYTHON SCRIPT: Connect to Multiple routers and Execute Multiple Commands
Full script is below
lab@admin:~$ cat T1
from netmiko import Netmiko
from getpass import getpass
username = input('Enter your SSH username: ')
password=getpass()
with open('Commands-to-run') as f:
commands_to_send = f.read().splitlines()
print (commands_to_send)
with open('Device-IP-List') as f:
devices = f.read().splitlines()
print (devices)
for router in devices:
print ('Connecting to device ====================" ' + router)
ip_address_of_device = router
junos_devices = {
'device_type': 'juniper_junos',
'ip': ip_address_of_device,
'username': username,
'password': password
}
all_devices = [junos_devices]
for devices in all_devices:
net_connect = Netmiko(**devices)
for x in commands_to_send:
output = net_connect.send_command(x) + "\n"
print(output)
net_connect.disconnect()
Watch video HOW TO Connect to "MULTIPLE ROUTERS" and Execute "MULTIPLE CLI COMMANDS" using SIMPLE PYTHON SCRIPT online without registration, duration hours minute second in high quality. This video was added by user Network Tips and Topics 01 March 2023, don't forget to share it with your friends and acquaintances, it has been viewed on our site 133 once and liked it 3 people.