Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| # ----------------------------- | |
| # Firewall Rules | |
| # ----------------------------- | |
| BLOCKED_IPS = ["192.168.1.10", "10.0.0.5"] | |
| ALLOWED_PORTS = [80, 443, 8080] | |
| # Store logs | |
| logs = [] | |
| # ----------------------------- | |
| # Firewall Function | |
| # ----------------------------- | |
| def firewall(ip, port): | |
| try: | |
| port = int(port) | |
| except: | |
| return "β οΈ Invalid port number" | |
| if not ip: | |
| return "β οΈ Please enter an IP address" | |
| # Rule checking | |
| if ip in BLOCKED_IPS: | |
| result = "β Blocked (IP is blacklisted)" | |
| elif port not in ALLOWED_PORTS: | |
| result = "β Blocked (Port not allowed)" | |
| else: | |
| result = "β Allowed" | |
| # Save logs | |
| logs.append(f"{ip}:{port} β {result}") | |
| # Show last 5 logs | |
| recent_logs = "\n".join(logs[-5:]) | |
| return f"{result}\n\nπ Recent Logs:\n{recent_logs}" | |
| # ----------------------------- | |
| # Gradio Interface | |
| # ----------------------------- | |
| iface = gr.Interface( | |
| fn=firewall, | |
| inputs=[ | |
| gr.Textbox(label="Enter IP Address", placeholder="e.g. 192.168.1.1"), | |
| gr.Textbox(label="Enter Port", placeholder="e.g. 80") | |
| ], | |
| outputs="text", | |
| title="π₯ Simple Firewall Simulator", | |
| description="Simulates firewall filtering using IP and Port rules.\nEnter values to check access.", | |
| ) | |
| # Run app | |
| iface.launch() | |