-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBackup-Network-Devices.py
36 lines (29 loc) · 974 Bytes
/
Backup-Network-Devices.py
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
# Alex Diker
# Instructions :
#
# Take automated backups of our network devices (switches, routers, wireless controllers)
#
#
import paramiko
import time
from getpass import getpass
username = 'cccc'
password = 'cccc'
DEVICE_LIST = open('2020-devices') # open device list
for RTR in DEVICE_LIST:
RTR = RTR.strip()
print("\n *** INFO:")
print("\n *** Connecting to device: " + RTR + '*****\n') # show you are connecting to device
SESSION = paramiko.SSHClient()
SESSION.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # add and show ssh connections/enter credentials
SESSION.connect(RTR,port=22,
username=username,
password=password,
look_for_keys=False,
allow_agent=False)
DEVICE_ACCESS = SESSION.invoke_shell()
DEVICE_ACCESS.send(b'|')
time.sleep(1)
output = DEVICE_ACCESS.recv(65000)
print(output.decode('ascii'))
SESSION.close()