-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreset.py
28 lines (24 loc) · 910 Bytes
/
reset.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
import ipaddress
import paramiko
import socket
import errno
from getpass import getpass
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
subnet = ipaddress.IPv4Network('192.168.39.0/24')
ip_address = [str(ip) for ip in subnet.hosts()]
user = input("Input Username: ")
passw = getpass()
for ip in ip_address:
try:
ssh.connect(hostname=ip, username=user, password=passw)
ssh.exec_command("system/reset-configuration no-defaults=yes skip-backup=yes")
except socket.error as e:
if e.errno == errno.EHOSTUNREACH:
print(f"Device {ip} is down or unreachable. Skipping...")
except Exception as e:
print(f"An error occurred while connecting to {ip}: {str(e)}")
finally:
ssh.close()
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())