gaurang671 commited on
Commit
18bba18
·
verified ·
1 Parent(s): e690da4

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +56 -0
  2. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ # -----------------------------
4
+ # Firewall Rules
5
+ # -----------------------------
6
+ BLOCKED_IPS = ["192.168.1.10", "10.0.0.5"]
7
+ ALLOWED_PORTS = [80, 443, 8080]
8
+
9
+ # Store logs
10
+ logs = []
11
+
12
+ # -----------------------------
13
+ # Firewall Function
14
+ # -----------------------------
15
+ def firewall(ip, port):
16
+ try:
17
+ port = int(port)
18
+ except:
19
+ return "⚠️ Invalid port number"
20
+
21
+ if not ip:
22
+ return "⚠️ Please enter an IP address"
23
+
24
+ # Rule checking
25
+ if ip in BLOCKED_IPS:
26
+ result = "❌ Blocked (IP is blacklisted)"
27
+ elif port not in ALLOWED_PORTS:
28
+ result = "❌ Blocked (Port not allowed)"
29
+ else:
30
+ result = "✅ Allowed"
31
+
32
+ # Save logs
33
+ logs.append(f"{ip}:{port} → {result}")
34
+
35
+ # Show last 5 logs
36
+ recent_logs = "\n".join(logs[-5:])
37
+
38
+ return f"{result}\n\n📜 Recent Logs:\n{recent_logs}"
39
+
40
+
41
+ # -----------------------------
42
+ # Gradio Interface
43
+ # -----------------------------
44
+ iface = gr.Interface(
45
+ fn=firewall,
46
+ inputs=[
47
+ gr.Textbox(label="Enter IP Address", placeholder="e.g. 192.168.1.1"),
48
+ gr.Textbox(label="Enter Port", placeholder="e.g. 80")
49
+ ],
50
+ outputs="text",
51
+ title="🔥 Simple Firewall Simulator",
52
+ description="Simulates firewall filtering using IP and Port rules.\nEnter values to check access.",
53
+ )
54
+
55
+ # Run app
56
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ gradio