Update app.py
Browse files
app.py
CHANGED
|
@@ -1,36 +1,42 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
| 2 |
import socket
|
| 3 |
-
import struct
|
| 4 |
|
| 5 |
-
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
def
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
|
|
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
s.sendto(send_data, (ip_address, 9))
|
| 25 |
|
| 26 |
-
|
| 27 |
-
def home():
|
| 28 |
-
return {"status": "Wake-on-LAN API جاهز 🚀"}
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
return {"success": False, "error": str(e)}
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
from wakeonlan import send_magic_packet
|
| 4 |
import socket
|
|
|
|
| 5 |
|
| 6 |
+
# بيانات جهازك
|
| 7 |
+
MAC = "dc:4a:3e:9a:eb:87"
|
| 8 |
+
PUBLIC_IP = "154.254.93.204"
|
| 9 |
|
| 10 |
+
def wake_pc():
|
| 11 |
+
try:
|
| 12 |
+
send_magic_packet(MAC)
|
| 13 |
+
return f"✅ Wake-on-LAN signal sent to {MAC} ({PUBLIC_IP})"
|
| 14 |
+
except Exception as e:
|
| 15 |
+
return f"❌ Error: {str(e)}"
|
| 16 |
|
| 17 |
+
def ping_pc():
|
| 18 |
+
try:
|
| 19 |
+
response = os.system(f"ping -c 1 {PUBLIC_IP}" if os.name != "nt" else f"ping -n 1 {PUBLIC_IP}")
|
| 20 |
+
if response == 0:
|
| 21 |
+
return f"✅ {PUBLIC_IP} is Online"
|
| 22 |
+
else:
|
| 23 |
+
return f"⚠️ {PUBLIC_IP} is Offline"
|
| 24 |
+
except Exception as e:
|
| 25 |
+
return f"❌ Error: {str(e)}"
|
| 26 |
|
| 27 |
+
# واجهة Gradio
|
| 28 |
+
with gr.Blocks() as demo:
|
| 29 |
+
gr.Markdown("## 🌐 Remote PC Controller (Wake-on-LAN + Ping)")
|
| 30 |
|
| 31 |
+
with gr.Row():
|
| 32 |
+
wake_btn = gr.Button("🔌 Wake PC")
|
| 33 |
+
ping_btn = gr.Button("📡 Ping PC")
|
|
|
|
| 34 |
|
| 35 |
+
output = gr.Textbox(label="Result")
|
|
|
|
|
|
|
| 36 |
|
| 37 |
+
wake_btn.click(fn=wake_pc, inputs=None, outputs=output)
|
| 38 |
+
ping_btn.click(fn=ping_pc, inputs=None, outputs=output)
|
| 39 |
+
|
| 40 |
+
# تشغيل Gradio
|
| 41 |
+
if __name__ == "__main__":
|
| 42 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|