@@ -97,6 +97,115 @@ This program uses `netsh` to manage firewall rules, which requires administrativ
9797 # Example:
9898 python main.py -i " Ethernet"
9999 ` ` `
100+
101+ # # 🍎 Running on macOS
102+
103+ This program uses ` pfctl` (Packet Filter Control) to manage firewall rules, which requires administrative privileges.
104+
105+ # ## Prerequisites
106+
107+ - ** macOS 10.5+**
108+ - ** Administrator privileges**
109+ - ** Python 3.6+**
110+
111+ # ## Setup Instructions
112+
113+ 1. ** Open Terminal:** Open the Terminal application (found in Applications > Utilities)
114+
115+ 2. ** Navigate to Project Directory:**
116+ ` ` ` bash
117+ cd path/to/simple_firewall
118+ ` ` `
119+
120+ 3. ** (Optional) Create Virtual Environment:**
121+ ` ` ` bash
122+ python3 -m venv venv
123+ source venv/bin/activate
124+ ` ` `
125+
126+ 4. ** Install Requirements:**
127+ ` ` ` bash
128+ pip install -r requirements.txt
129+ ` ` `
130+
131+ 5. ** Create Configuration File:**
132+ ` ` ` bash
133+ python3 main.py --create-config
134+ ` ` `
135+
136+ 6. ** Run the Firewall:**
137+ ` ` ` bash
138+ sudo python3 main.py
139+ ` ` `
140+
141+ Or specify an interface:
142+ ` ` ` bash
143+ sudo python3 main.py -i en0
144+ ` ` `
145+
146+ # ## macOS Firewall Management
147+
148+ The firewall uses ` pfctl` to manage blocking rules:
149+
150+ - ** Automatic Setup:** On first run, the firewall automatically:
151+ - Creates a ` blocked_ips` table in pfctl
152+ - Enables pfctl if not already enabled
153+ - Loads blocking rules from a temporary configuration file
154+
155+ - ** Blocking Mechanism:** IPs are added to a pfctl table, and rules block all traffic from/to those IPs
156+
157+ - ** Automatic Cleanup:** When the firewall stops, all blocked IPs are automatically removed
158+
159+ # ## Managing pfctl Manually
160+
161+ If you need to manually manage the firewall:
162+
163+ ` ` ` bash
164+ # View currently blocked IPs
165+ sudo pfctl -t blocked_ips -T show
166+
167+ # Remove a specific IP manually
168+ sudo pfctl -t blocked_ips -T delete < IP_ADDRESS>
169+
170+ # Flush all blocked IPs
171+ sudo pfctl -t blocked_ips -T flush
172+
173+ # Check pfctl status
174+ sudo pfctl -s info
175+
176+ # View current rules
177+ sudo pfctl -s rules
178+ ` ` `
179+
180+ # ## Troubleshooting macOS
181+
182+ ** Issue: " pfctl: command not found" **
183+ - This shouldn' t happen on macOS, but if it does, ensure you' re running a supported macOS version
184+
185+ ** Issue: " pfctl: Permission denied" **
186+ - Make sure you' re running with `sudo`
187+ - Some macOS versions may require additional permissions
188+
189+ **Issue: "pfctl: cannot enable"**
190+ - macOS System Preferences may have the built-in firewall enabled
191+ - You may need to disable it in System Preferences > Security & Privacy > Firewall
192+ - Or allow pfctl to run by granting Full Disk Access in System Preferences
193+
194+ **Issue: Interface not found**
195+ - List available interfaces: `ifconfig` or `networksetup -listallhardwareports`
196+ - Common macOS interfaces: `en0` (Ethernet), `en1` (Wi-Fi), `en2` (USB Ethernet)
197+
198+ **Issue: Blocks not working**
199+ - Check if pfctl is enabled: `sudo pfctl -s info`
200+ - Verify rules are loaded: `sudo pfctl -s rules`
201+ - Check if IPs are in the table: `sudo pfctl -t blocked_ips -T show`
202+
203+ ### macOS-Specific Notes
204+
205+ - **System Firewall:** macOS has a built-in firewall in System Preferences. The Simple Firewall works alongside it but uses pfctl directly
206+ - **Interface Names:** macOS uses names like `en0`, `en1`, etc. (not `eth0` like Linux)
207+ - **Root Access:** Always run with `sudo` for firewall operations
208+ - **Temporary Rules:** The firewall creates temporary pf.conf files that are automatically managed
100209
101210## Usage
102211
@@ -125,6 +234,49 @@ python3 main.py --create-config
125234sudo python3 main.py -v
126235```
127236
237+ # 🐳 Running with Docker
238+
239+ Using Docker is the recommended way to run the firewall, as it automatically manages all dependencies and network permissions.
240+
241+ ---
242+
243+ ## ✅ Prerequisites
244+
245+ Make sure you have the following installed:
246+
247+ - **Docker**
248+ - **Docker Compose**
249+ *(Docker Desktop for Windows/macOS includes both.)*
250+
251+ ---
252+
253+
254+ ### **1. Build and Run**
255+
256+ Open your terminal in the project’s root directory and run:
257+
258+ ```bash
259+ docker-compose run --rm firewall
260+ ```
261+
262+ The image will build the **first time** you run this command.
263+
264+ `--rm` ensures the container is automatically removed when it stops.
265+
266+ ---
267+
268+ ## 2. Select Network Interface
269+
270+ After the container starts, you will be prompted to choose the interface:
271+
272+ Select an interface (0–2): 2
273+
274+
275+ ---
276+
277+ ## ✅ To Stop
278+
279+ Press: Ctrl + C
128280
129281
130282## Configuration
@@ -263,8 +415,11 @@ src/
263415# # Requirements
264416
265417- ** Python 3.6+**
266- - ** Root privileges** (required for iptables access)
267- - ** Linux system** (uses iptables for blocking)
418+ - ** Root/Administrator privileges** (required for firewall access)
419+ - ** Supported Platforms:**
420+ - ** Linux:** Uses iptables for blocking
421+ - ** macOS:** Uses pfctl (Packet Filter) for blocking
422+ - ** Windows:** Uses netsh (Windows Firewall) for blocking
268423
269424# ## Python Packages:
270425- ` scapy` - Packet capture and analysis
@@ -346,6 +501,27 @@ sudo iptables -D INPUT -s [IP_ADDRESS] -j DROP
346501sudo iptables -F INPUT
347502` ` `
348503
504+ ** macOS (pfctl):**
505+ ` ` ` bash
506+ # View blocked IPs in table
507+ sudo pfctl -t blocked_ips -T show
508+
509+ # Remove specific IP
510+ sudo pfctl -t blocked_ips -T delete [IP_ADDRESS]
511+
512+ # Flush all blocked IPs
513+ sudo pfctl -t blocked_ips -T flush
514+ ` ` `
515+
516+ ** Windows (netsh):**
517+ ` ` ` powershell
518+ # List firewall rules
519+ netsh advfirewall firewall show rule name=all
520+
521+ # Delete specific rule (replace IP_ADDRESS with actual IP)
522+ netsh advfirewall firewall delete rule name=" SimpleFirewall_Block_[IP_ADDRESS]"
523+ ` ` `
524+
349525# # Current Limitations & Known Issues
350526
351527⚠️ ** Platform Limitations:**
@@ -405,6 +581,7 @@ This is an **educational open-source project** designed to help people learn net
405581- ** Performance:** Optimize packet processing and memory usage
406582- ** Testing:** Add unit tests and integration tests
407583- ** Documentation:** Improve code comments and examples
584+ - ** IPv6 Support:** Extend blocking to IPv6 addresses
408585
409586# ## 📋 **Current Architecture Issues to Fix:**
410587- Replace hardcoded magic numbers with named constants
0 commit comments