api layer v0.2.4 - /nettools endpoint

This commit is contained in:
jokob-sk
2025-08-20 08:40:14 +10:00
parent a2bccdfb8e
commit 2fa181ffbc
5 changed files with 145 additions and 1 deletions

View 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