mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
22 lines
681 B
Python
Executable File
22 lines
681 B
Python
Executable File
import subprocess
|
|
import re
|
|
from flask import jsonify
|
|
|
|
def wakeonlan(mac):
|
|
|
|
# Validate MAC
|
|
if not re.match(r'^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$', mac):
|
|
return jsonify({"success": False, "error": f"Invalid MAC: {mac}"}), 400
|
|
|
|
try:
|
|
result = subprocess.run(
|
|
["wakeonlan", mac],
|
|
capture_output=True,
|
|
text=True,
|
|
check=True
|
|
)
|
|
return jsonify({"success": True, "message": "WOL packet sent", "output": result.stdout.strip()})
|
|
except subprocess.CalledProcessError as e:
|
|
return jsonify({"success": False, "error": "Failed to send WOL packet", "details": e.stderr.strip()}), 500
|
|
|