Add wifi.py

This commit is contained in:
2025-10-03 01:06:56 +00:00
parent 3117a49ac3
commit 4c53a83a0a
+34
View File
@@ -0,0 +1,34 @@
#!/usr/bin/env python3
import paramiko
import datetime
# Device connection info
DEVICE_IP = "192.168.100.251"
USERNAME = "stahlz"
PASSWORD = "ZlNOBgEsbZ6ISXj0"
REBOOT_CMD = "sudo /sbin/reboot"
LOGFILE = "unifi-reboot.log"
def log(message):
timestamp = datetime.datetime.now().strftime("[%Y-%m-%d %H:%M:%S]")
with open(LOGFILE, "a") as f:
f.write(f"{timestamp} {message}\n")
print(f"{timestamp} {message}")
def reboot_device():
log(f"Rebooting {DEVICE_IP} (user: {USERNAME})...")
try:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(DEVICE_IP, username=USERNAME, password=PASSWORD, timeout=10)
stdin, stdout, stderr = ssh.exec_command(REBOOT_CMD)
output = stdout.read().decode().strip()
ssh.close()
log(f"SUCCESS: {DEVICE_IP} reboot command sent.")
log(f"Output: {output}")
except Exception as e:
log(f"ERROR: Failed to reboot {DEVICE_IP}. Reason: {e}")
log(f"Error: {e}")
if __name__ == "__main__":
reboot_device()