import gradio as gr from wakeonlan import send_magic_packet from flask_limiter import Limiter from flask_limiter.util import get_remote_address from flask import Flask, request import time # Setup Flask app for rate-limiting security app = Flask(__name__) # Limiter: max 5 requests per minute from the same IP limiter = Limiter( get_remote_address, app=app, default_limits=["5 per minute"] ) # Define your PC's MAC address and a password for security MAC_ADDRESS = "XX:XX:XX:XX:XX:XX" # Replace with your PC's MAC address PASSWORD = "your_secure_password" # Set a strong password # Function to wake up the PC using WOL def wake_pc(password): if password == PASSWORD: try: send_magic_packet(MAC_ADDRESS) return "Wake-on-LAN packet sent! PC should be waking up." except Exception as e: return f"Error sending WOL packet: {str(e)}" else: return "Incorrect password. Access denied." # Security: Apply rate-limiting to the WOL function @app.route('/wol', methods=['POST']) @limiter.limit("5 per minute") # Restrict WOL usage to prevent abuse def wake_on_lan(): password = request.form.get('password', '') return wake_pc(password) # Gradio interface setup def wol_interface(password): # Calls the Flask endpoint for rate-limiting protection return wake_pc(password) # Create a Gradio interface with password input interface = gr.Interface( fn=wol_interface, inputs=gr.Password(label="Enter Password"), # Password input outputs="text", title="Wake On LAN", description="Use this to wake your PC remotely via Wake-on-LAN. Access is restricted with a password." ) if __name__ == "__main__": interface.launch(share=True) # Use share=True to expose publicly