A real-time Network Intrusion Detection System built with Python, MySQL, and Grafana. Monitors live network traffic and detects suspicious activities such as port scans, brute force attempts, and unknown IP addresses.
- Live packet capture using Scapy
- Detection of Port Scan, Brute Force, and Unknown IP attacks
- Real-time alerts via console and email
- MySQL database logging for all packets and alerts
- Grafana dashboard for visualization
NIDS-Project/
├── alerts/
│ └── alert_manager.py # Email and file logging
├── capture/
│ └── packet_capture.py # Scapy packet capture
├── database/
│ └── db_handler.py # MySQL connection and queries
├── detection/
│ └── rules.py # Detection rules
├── tests/
│ └── simulate_attacks.py # Attack simulation scripts
├── visualization/
│ └── dashboard.json # Grafana dashboard import
├── logs/ # Alert logs (auto-generated and gitignored)
├── config.py # Local config (gitignored)
├── config.example.py # Config template
├── schema.sql # Database schema
├── main.py # Entry point
└── requirements.txt # Python dependencies
- Python 3.10+
- MySQL 8.0+
- Grafana OSS
- Npcap (for packet capture on Windows)
- Wireshark (optional, for debugging)
git clone https://github.com/hasnain-098/NIDS-Project.git
cd NIDS-Projectpip install -r requirements.txtOpen MySQL Workbench and run:
schema.sqlcopy config.example.py config.pyEdit config.py and fill in:
- MySQL password
- Your network IPs for whitelist
- Gmail app password for email alerts
- Open Grafana at
http://localhost:3000 - Go to Dashboards → Import
- Upload
visualization/dashboard.json - Select MySQL as data source
python main.pyMake sure main.py is running, then in a separate terminal:
python tests/simulate_attacks.pyOr use nmap for port scan simulation:
nmap -Pn -sS -T4 --top-ports 5000 <target-ip>| Attack Type | Rule | Severity |
|---|---|---|
| Port Scan | More than 10 unique ports within 120 seconds | HIGH |
| Brute Force | More than 5 attempts on sensitive ports within 2 minutes | CRITICAL |
| Unknown IP | Traffic from IP not in whitelist | LOW |
| Category | Tool |
|---|---|
| Language | Python 3.10+ |
| Packet Capture | Scapy, Npcap |
| Database | MySQL 8.0 |
| Visualization | Grafana OSS |
| Debugging | Wireshark |
| Version Control | Git, GitHub |
Data Communication and Computer Networks (DCCN)
DHA Suffa University — Spring 2026
- Hasnain Memon — CS231007
- Pirthum Kumar — CS231127
- Sahil Kumar — CS231135
- Sangeet Kumar — CS231109