Production-ready network security platform with ML-powered threat detection, real-time flow visualization, and a full REST API — for Windows and Linux.
NetGuard IDS is a fully-featured, production-grade network security tool that combines stateful firewall control with a multi-layer intrusion detection engine — including rule-based detection, ML anomaly scoring, and Deep Packet Inspection — all wrapped in a modern dark-themed GUI, a FastAPI REST backend, and a Typer CLI.
- Features
- Architecture
- Quick Start
- Installation Options
- Configuration
- REST API
- CLI Reference
- Detection Engine
- Performance
- Docker
- Testing
- Security
- Contributing
|
🔥 Firewall Control
🕵️ Intrusion Detection (3 layers)
🔬 Deep Packet Inspection
|
🌐 Network Flow Graph
🤖 ML Advanced Features
🖥️ Three Frontends
|
|
🔌 Plugin Architecture
📊 Monitoring & Alerts
|
📦 Deployment
🔒 Security
|
netguard-ids/
├── main.py # GUI entry point
├── config.yaml # All settings (hot-reloaded)
├── rules/ # YAML rule files (hot-reloaded)
│
├── core/ # Business logic — zero Qt dependency
│ ├── engine.py # NetGuardEngine — orchestrates all layers
│ ├── app_runner.py # Thread manager (engine + API + watcher)
│ ├── event_bus.py # Typed pub/sub event bus
│ ├── firewall.py # Cross-platform firewall abstraction
│ ├── firewall_windows.py # netsh backend
│ ├── firewall_linux.py # iptables backend
│ ├── ids.py # IDS worker (threshold + port scan)
│ ├── rule_engine.py # YAML rule evaluation
│ ├── detector_abc.py # AbstractDetector + DetectorResult
│ ├── detector_registry.py # Plugin registry + entry-point discovery
│ ├── dpi_plugin.py # Deep Packet Inspection detector
│ ├── advanced_features.py # ConfigWatcher, MLABTester, ActiveLearningQueue
│ ├── anomaly.py # ML anomaly detector (IsolationForest/ECOD)
│ ├── alert_manager.py # Alert persistence + querying
│ ├── blocklist.py # SQLite block/alert store
│ ├── whitelist.py # IP whitelist (checked before all detection)
│ ├── geo.py # IP geolocation + caching
│ ├── scheduler.py # Time-based firewall rule scheduler
│ └── notifier.py # Desktop / email / SMS alerts
│
├── ui/ # PySide6 GUI (10 tabs)
│ ├── main_window.py # Tabbed main window + engine wiring
│ ├── dashboard_tab.py # Live connections + graph
│ ├── rules_tab.py # Firewall rule management
│ ├── rule_editor_tab.py # YAML rule editor
│ ├── alerts_tab.py # Alert history + export
│ ├── blocklist_tab.py # Block / unblock IPs
│ ├── scheduler_tab.py # Time-based rules
│ ├── threat_map_tab.py # World map of blocked IPs
│ ├── flow_visualization_tab.py# Force-directed network graph ← NEW
│ ├── plugin_manager_tab.py # Plugin enable/disable/install ← NEW
│ ├── settings_tab.py # Config editor
│ └── event_bus_bridge.py # Thread-safe Qt signal bridge
│
├── api/ # FastAPI REST + WebSocket
│ └── server.py # OpenAPI, streaming, API-key auth
│
├── cli/ # Typer CLI
│ └── main.py # Commands: engine, rules, blocklist, watch
│
├── utils/
│ ├── logger.py # Rotating JSON logger
│ ├── config_loader.py # YAML loader with schema validation
│ ├── exporter.py # CSV / PDF export
│ └── validators.py # IP / CIDR validation
│
├── tests/ # 447 pytest tests (446 passing)
├── benchmarks/ # Performance benchmark suite
├── packaging/
│ ├── windows/ # WiX MSI + build_installer.ps1
│ └── linux/ # .deb build script + .rpm spec
└── docs/ # MkDocs Material documentation site
Network Connection Event
│
▼
┌─────────────────┐ whitelist? ┌─────────────┐
│ IP Whitelist │ ──── YES ──────► │ Allow (log)│
└─────────────────┘ └─────────────┘
│ NO
▼
┌─────────────────┐
│ ThresholdIDS │ (sliding window, port-scan, SYN flood)
└────────┬────────┘
│
▼
┌─────────────────┐
│ Rule Engine │ (YAML declarative rules, hot-reloaded)
└────────┬────────┘
│
▼
┌─────────────────┐
│ ML Anomaly │ (IsolationForest / ECOD — optional)
└────────┬────────┘
│
▼
┌─────────────────┐
│ DPI Plugin │ (7 payload signatures, C2 beacon, port heuristics)
└────────┬────────┘
│
▼
┌─────────────────┐ triggered? ┌───────────────────────┐
│ DetectorResult │ ── YES ──────► │ Alert / Block / Notify │
└─────────────────┘ └───────────────────────┘
| Requirement | Windows | Linux |
|---|---|---|
| Python | 3.10+ (in PATH) | 3.10+ |
| Privilege | Run as Administrator | Run with sudo / CAP_NET_ADMIN |
| Firewall | Windows Firewall enabled | iptables installed |
# Core engine only (headless, no GUI)
pip install netguard-ids
# With GUI
pip install "netguard-ids[gui]"
# Everything
pip install "netguard-ids[gui,api,cli,ml]"git clone https://github.com/Armanrbu/Firewall-Configuration-and-Basic-Intrusion-Detection-System.git
cd Firewall-Configuration-and-Basic-Intrusion-Detection-System
pip install -e ".[gui,api,cli,ml,dev]"
# Launch GUI
python main.py
# Or use CLI
netguard-cli engine start| Method | Command | Best for |
|---|---|---|
| PyPI | pip install "netguard-ids[gui]" |
Quick install, any OS |
| Source | git clone + pip install -e . |
Development |
| Docker | docker compose up |
Headless / server deploy |
| Windows MSI | packaging/windows/build_installer.ps1 |
End-user Windows install |
| Linux .deb | packaging/linux/build_deb.sh |
Ubuntu / Debian |
| Linux .rpm | packaging/linux/netguard-ids.spec |
Fedora / RHEL |
Copy .env.example → .env and set any secrets:
cp .env.example .envEdit config.yaml — changes are hot-reloaded within 3 seconds (no restart needed):
ids:
alert_threshold: 10 # Connections/window before flagging
time_window_seconds: 60 # Sliding window duration
auto_block: false # Auto-block flagged IPs (off by default)
port_scan_threshold: 15 # Distinct ports to trigger scan alert
ml:
enabled: true
model: isolation_forest # or: ecod
contamination: 0.01 # Expected anomaly fraction
dpi:
enabled: true # Deep Packet Inspection
c2_variance_threshold: 200 # ms — lower = stricter beacon detection
api:
enabled: false # Enable REST API
port: 8000
api_key: "" # Auto-generated on first start if empty
notifications:
desktop: true
email:
enabled: false
smtp_host: smtp.gmail.com
smtp_port: 587Start the API via Settings tab or CLI:
netguard-cli api start --port 8000Interactive docs at http://localhost:8000/docs (Swagger UI).
| Method | Endpoint | Description |
|---|---|---|
GET |
/status |
Engine status + active connections |
GET |
/blocked |
All blocked IPs |
POST |
/block |
Block an IP {"ip": "1.2.3.4", "reason": "..."} |
POST |
/unblock |
Unblock an IP |
GET |
/alerts |
Recent alerts (filterable) |
GET |
/connections |
Live connection snapshot |
GET |
/detectors |
Registered plugins + status |
WS |
/ws/stream |
WebSocket — real-time event stream |
All endpoints require: X-API-Key: <your_key>
# Example
curl -H "X-API-Key: your-key" http://localhost:8000/status | jqnetguard-cli --help
# Engine
netguard-cli engine start # Start the detection engine (headless)
netguard-cli engine stop
netguard-cli engine status
# Rules
netguard-cli rules list
netguard-cli rules add --ip 1.2.3.4 --action block --name "bad actor"
netguard-cli rules remove --id 42
# Blocklist
netguard-cli blocklist show
netguard-cli blocklist block 1.2.3.4
netguard-cli blocklist unblock 1.2.3.4
# Live monitoring
netguard-cli watch # Tail live alerts (rich table)
netguard-cli watch --filter alert # Filter by severityWrite a custom detector in 10 lines:
from core.detector_abc import AbstractDetector, DetectorResult
class MyDetector(AbstractDetector):
name = "my_detector"
version = "1.0.0"
def analyze(self, ip, events, *, context=None):
score = len(events) / 100.0
return DetectorResult(
triggered=score > 0.5,
score=score,
reason="too many connections",
action="alert",
)Register via pyproject.toml entry-point:
[project.entry-points."netguard.detectors"]
my_detector = "my_package.detector:MyDetector"Then install your package — NetGuard auto-discovers it at startup.
from core.advanced_features import MLABTester
tester = MLABTester(champion_detector, challenger_detector, min_samples=500)
result = tester.run(ip, events) # Routes to both, returns champion result
summary = tester.summary() # agreement_rate, win counts
winner = tester.choose_champion() # Promote winner after enough samplesfrom core.advanced_features import ConfigWatcher
watcher = ConfigWatcher(
paths=["config.yaml", "rules/"],
on_change=lambda changed: engine.reload_rules(),
poll_interval=3.0,
)
watcher.start()Benchmarked on Windows 10, Python 3.10, AMD64 (7/7 passing):
| Component | Mean Latency | p99 Latency | Throughput |
|---|---|---|---|
| Threshold Detector | 0.03 ms | < 1 ms | > 10,000 /s |
| Rule Engine | 0.002 ms | < 5 ms | > 50,000 /s |
| DPI Detector | 0.07 ms | < 3 ms | > 5,000 /s |
| Event Bus | 0.004 ms | < 2 ms | > 50,000 /s |
| Config Loader | 1.3 ms | < 50 ms | > 700 /s |
| ML A/B Tester | 0.04 ms | < 10 ms | > 20,000 /s |
Run benchmarks yourself:
python benchmarks/benchmark_suite.py
# Results saved to benchmarks/results/benchmark_<timestamp>.json# Start everything (engine + API)
docker compose up -d
# Engine only (headless)
docker run --rm --cap-add NET_ADMIN \
-v $(pwd)/config.yaml:/app/config.yaml:ro \
ghcr.io/armanrbu/netguard-ids:latest \
netguard-cli engine start --headlessdocker-compose.yml mounts config.yaml and rules/ live — edit them and changes apply in ≤ 3s via hot-reload.
# Run all tests
pytest tests/ -v
# With coverage report
pytest tests/ --cov=. --cov-report=html
# Run benchmarks
python benchmarks/benchmark_suite.py
# Specific module
pytest tests/test_advanced_features.py -vTest stats: 447 tests · 446 passing · 1 known Windows temp-path flake in test_ml_detector.py
NetGuard IDS has been audited against the OWASP Top 10 (2021):
| Category | Status |
|---|---|
| A01 Broken Access Control | ✅ Passed (API key auth, non-root Docker) |
| A02 Cryptographic Failures | ✅ Passed (no hardcoded secrets, TLS-ready) |
| A03 Injection | ✅ Passed (parameterised SQL, safe_load, no shell=True) |
| A04 Insecure Design | ✅ Passed (whitelist-first, auto-block off by default) |
| A05 Security Misconfiguration | ✅ Passed (secure defaults, minimal Docker EXPOSE) |
| A06 Vulnerable Components | ✅ Passed (Dependabot + pip-audit in CI) |
| A07 Auth Failures | ✅ Passed (secrets.compare_digest, auto-generated key) |
| A08 Software Integrity | ✅ Passed (OIDC PyPI publish, entry-point validation) |
| A09 Logging Failures | ✅ Passed (structured JSON logs, alert persistence) |
| A10 SSRF | ✅ Passed (no outbound requests to user-supplied URLs) |
Result: 56/58 controls passed. Full audit: docs/security-audit.md
To report a vulnerability: see SECURITY.md.
Contributions welcome! Please read CONTRIBUTING.md first.
# Setup dev environment
pip install -e ".[dev]"
# Run linter
ruff check .
# Run type-checker
mypy core/ ui/ api/ cli/
# Run tests
pytest tests/ -qSee CHANGELOG.md for version history.
Arman — Computer Engineer · Security Research · Systems Programming
MIT License — free for personal and commercial use.
If NetGuard IDS helped you, please ⭐ star the repo!
Built with ❤️ and Python