gaurang671's picture
Upload 2 files
18bba18 verified
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()