A Python-based simulation of a rule-based firewall designed to monitor and control network traffic. This project includes both a command-line interface (CLI) and a graphical user interface (GUI) for rule management, along with traffic logging and analytics. Check this video to See the demonstration: https://youtu.be/SD6IPPylr8w
- Rule-Based Access Control: Blocks or allows traffic based on predefined rules stored in a JSON file.
- Traffic Simulation: Generates random traffic to test firewall behavior.
- Logging: Records all actions (block/allow) in a log file for auditing purposes.
- GUI Management: Provides a user-friendly interface for visualizing and managing rules.
- Extensibility: Modular design supports future enhancements like wildcard rules and real-time traffic monitoring.
basic_firewall/
├── firewall.py # Main script for console-based simulation
├── firewall_gui.py # GUI version of the firewall
├── rules.json # JSON file to store firewall rules
├── traffic.log # Log file for traffic actions (auto-created)
└── traffic_generator.py # Optional traffic generation module
firewall.py: Enforces firewall rules and logs actions.firewall_gui.py: Provides a graphical interface for managing rules.rules.json: Stores firewall rules in a structured format.traffic.log: Captures details of all traffic actions for auditing.traffic_generator.py: Simulates random traffic for testing purposes.
Rules are stored in rules.json and define actions for specific IP addresses:
{
"192.168.1.1": "block",
"192.168.1.4": "block",
"192.168.1.9": "block",
"192.168.1.13": "block",
"192.168.1.16": "block",
"192.168.1.19": "block"
}- Key: Represents the IP address.
- Value: Specifies the action (
blockorallow).
Traffic actions are logged in traffic.log with details like timestamps, IP addresses, and actions:
2024-12-07 00:42:25 - IP: 192.168.1.19, Action: block
2024-12-07 00:42:25 - IP: 192.168.1.8, Action: allow
- Python Version: Python 3.6 or higher.
- Libraries:
tkinter(default in most Python installations),matplotlib(for analytics).
- Clone or download the repository:
git clone https://github.com/dev0558/basic_firewall.git cd basic_firewall - Install required dependencies:
pip install matplotlib
- (Optional) Set up a virtual environment:
python3 -m venv env source env/bin/activate # On Linux/Mac env\Scripts\activate # On Windows
Execute the script to simulate traffic:
python3 firewall.pyStart the graphical user interface:
python3 firewall_gui.pyGenerate random traffic for testing:
python3 traffic_generator.pyInspect traffic logs for recorded actions:
cat traffic.log- Accurately enforces predefined rules.
- Provides intuitive GUI for rule management.
- Logs ensure traceability and transparency.
- Ensuring immediate effect of rule changes in the GUI.
- Handling larger rule sets or wildcard matching.
- Optimizing GUI responsiveness for heavy traffic.
- Add wildcard rule support (e.g.,
192.168.*). - Integrate with live traffic monitoring tools.
- Introduce threat intelligence integration for blocking malicious IPs.
Contributions are welcome! Please fork the repository and create a pull request for review.
This project is licensed under the MIT License. See the LICENSE file for details.