-
Notifications
You must be signed in to change notification settings - Fork 1
/
Netmiko_cisco_ios_command_run
44 lines (32 loc) · 1.34 KB
/
Netmiko_cisco_ios_command_run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/home/repos/public/Python/bin/python3.6
#
from netmiko import Netmiko
from getpass import getpass
def connect_device(device, command):
host = {"ip":device.strip(), "username":username, "password":password, "device_type":"cisco_ios", "secret":enable}
# for SLOW links
# host = {"ip":device.strip(), "username":username, "password":password, "device_type":"cisco_ios", "secret":enable, "global_delay_factor":5}
try:
net_connect = Netmiko(**host)
net_connect.enable()
output = net_connect.send_command(command)
return output
except Exception as ex:
print(f"{device} connection FAILED! - Error message: ", ex)
commands = ["ping 1.1.1.1", "show ip interface brief"] # sample list of commands
devices = ["device1", "device2"] # sample list of devices
username = input("Username: ")
password = getpass("TACACS+ Password: ")
enable = getpass("Enable Secret: ")
for device in devices:
for command in commands:
print(device)
print("---------------------------------------------------------------------")
print(connect_device(device, command))
print()
# In order to run for many devices in parallel use concurrent.futures
"""
import concurrent.futures
with concurrent.futures.ThreadPoolExecutor(5) as executor:
executor.map(connect_device, devices)
"""