mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
api layer v0.2.4 - /nettools endpoint
This commit is contained in:
21
server/api_server/nettools_endpoint.py
Executable file
21
server/api_server/nettools_endpoint.py
Executable file
@@ -0,0 +1,21 @@
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user