A C++ Deep Packet Inspection (DPI) engine that reads network captures, classifies traffic by application (YouTube, Netflix, TikTok, etc.), enforces blocking rules, and writes a filtered output PCAP. Ships with a full-stack web dashboard: upload a .pcap, set rules, and get instant traffic analytics with charts, flow tables, and download links.
- Protocol parsing β Ethernet/IPv4/TCP/UDP from raw PCAP bytes, zero external libraries
- TLS SNI extraction β identifies encrypted HTTPS destinations (YouTube, Facebook, 20+ apps) from the plaintext Client Hello field
- HTTP Host header extraction β classifies unencrypted HTTP traffic
- Flow-based blocking β block by app, source IP, or domain substring; all packets of a matched flow are dropped
- Two engine variants β single-threaded for simplicity, multi-threaded (LB β FP pipeline) for performance
- Structured JSON output β
--json <path>flag emits a machine-readable report from both engines - Web dashboard β FastAPI backend + single-file HTML/JS frontend; upload a pcap, run the engine, view charts and flow tables, download the filtered pcap
βββββββββββββββ ββββββββββββββββββββββββββββββββ βββββββββββββββ
β input.pcap βββββΊβ DPI Engine (C++) βββββΊβ output.pcap β
βββββββββββββββ β Β· Parse headers β βββββββββββββββ
β Β· Extract TLS SNI β βββββββββββββββ
β Β· Classify to app βββββΊβ report.json β
β Β· Apply blocking rules β βββββββββββββββ
ββββββββββββββββββββββββββββββββ
β²
ββββββββββββββββ΄βββββββββββββββ
β Web Dashboard (optional) β
β FastAPI backend + HTML UI β
βββββββββββββββββββββββββββββββ
Multi-threaded engine pipeline:
Reader β [LB0, LB1, ...] β [FP0, FP1, FP2, FP3, ...] β Output Writer
(hash by 5-tuple for consistent flow assignment)
Packet_analyzer/
βββ include/ # C++ headers
β βββ types.h # FiveTuple, AppType, BlockingRules
β βββ pcap_reader.h # PCAP file I/O
β βββ packet_parser.h # Ethernet/IP/TCP/UDP parsing
β βββ sni_extractor.h # TLS SNI + HTTP Host extraction
β βββ json_writer.h # Lightweight JSON serializer (no deps)
β βββ thread_safe_queue.h # Lock-free queue for MT engine
β βββ load_balancer.h # LB thread (MT engine)
β βββ fast_path.h # FP thread (MT engine)
β
βββ src/
β βββ main_working.cpp # β
Simple single-threaded engine
β βββ dpi_mt.cpp # β
Multi-threaded LB/FP engine
β βββ packet_parser.cpp
β βββ sni_extractor.cpp
β βββ pcap_reader.cpp
β βββ types.cpp
β
βββ web/
β βββ backend/
β β βββ main.py # FastAPI: upload β engine β JSON
β β βββ requirements.txt
β β βββ bin/ # Place compiled binaries here
β βββ frontend/
β β βββ index.html # Single-file dashboard (Chart.js)
β βββ README.md # Web dashboard docs
β
βββ generate_test_pcap.py # Generates test_dpi.pcap
βββ test_dpi.pcap # Sample capture (multi-protocol)
βββ CMakeLists.txt
# Simple engine
g++ -std=c++17 -O2 -I include -o dpi_simple \
src/main_working.cpp src/pcap_reader.cpp src/packet_parser.cpp \
src/sni_extractor.cpp src/types.cpp
# Multi-threaded engine
g++ -std=c++17 -pthread -O2 -I include -o dpi_engine \
src/dpi_mt.cpp src/pcap_reader.cpp src/packet_parser.cpp \
src/sni_extractor.cpp src/types.cppOr with CMake:
mkdir build && cd build && cmake .. && cmake --build .# Basic analysis
./dpi_simple test_dpi.pcap output.pcap
# Block YouTube and a specific IP, export JSON report
./dpi_engine test_dpi.pcap output.pcap \
--block-app YouTube \
--block-ip 192.168.1.50 \
--block-domain tiktok \
--json report.json \
--lbs 2 --fps 2# Copy binaries to the web backend
cp dpi_simple web/backend/bin/
cp dpi_engine web/backend/bin/
# Install and run
cd web/backend
pip install -r requirements.txt
uvicorn main:app --port 8123Open http://127.0.0.1:8123 β drag in a pcap, add block rules, click Analyze.
Both engines share the same flags:
| Flag | Description |
|---|---|
--block-app <name> |
Block app by name (YouTube, Netflix, TikTok, Facebook, etc.) |
--block-ip <ip> |
Block all traffic from a source IP |
--block-domain <str> |
Block any flow whose SNI contains this substring |
--json <path> |
Write structured JSON report to this path |
Additional flags for dpi_engine (multi-threaded):
| Flag | Default | Description |
|---|---|---|
--lbs <n> |
2 | Number of Load Balancer threads |
--fps <n> |
2 | Number of Fast Path threads per LB |
{
"engine": "multi-threaded",
"total_packets": 77,
"forwarded": 75,
"dropped": 2,
"app_breakdown": [
{ "app": "HTTPS", "count": 39, "percent": 50.6 },
{ "app": "YouTube", "count": 4, "percent": 5.2 }
],
"detected_domains": [
{ "domain": "www.youtube.com", "app": "YouTube" }
],
"blocked_events": [
{ "src_ip": "10.0.0.5", "dest_ip": "142.250.185.206", "app": "YouTube", "sni": "www.youtube.com" }
],
"flows": [
{ "src_ip": "10.0.0.5", "dest_ip": "31.13.64.35", "src_port": 52341,
"dest_port": 443, "protocol": "TCP", "app": "Facebook",
"sni": "www.facebook.com", "packets": 6, "bytes": 1240, "blocked": false }
],
"load_balancers": [{ "id": 0, "dispatched": 53 }],
"fast_paths": [{ "id": 0, "processed": 53 }]
}The FastAPI backend exposes three endpoints:
| Endpoint | Description |
|---|---|
POST /api/analyze |
Upload pcap + rules β returns JSON report |
GET /api/runs/{id}/output.pcap |
Download filtered output pcap |
GET /api/runs/{id}/report.json |
Download raw JSON report |
GET /api/health |
Check which engine binaries are available |
POST /api/analyze form fields: pcap (file), engine (simple/multi-threaded), block_apps, block_ips, block_domains (comma-separated strings), lbs, fps (integers).
Even though HTTPS traffic is encrypted, the destination domain is sent in plaintext during the TLS handshake (the Client Hello message). We parse the raw bytes to find the SNI (Server Name Indication) extension:
TLS Client Hello β Extensions β Type 0x0000 (SNI) β "www.youtube.com"
We track flows by their 5-tuple (src IP, dst IP, src port, dst port, protocol). Once a flow is classified (e.g., as YouTube), every subsequent packet belonging to it is dropped β not just the one containing the Client Hello.
The MT engine distributes flows across threads using consistent hashing on the 5-tuple: hash(flow) % num_lbs picks a Load Balancer, then hash(flow) % fps_per_lb picks a Fast Path. This guarantees all packets of one flow land on the same FP thread, keeping flow state safe without locking.
YouTube, Netflix, TikTok, Facebook, Instagram, Twitter, WhatsApp, Google, GitHub, Amazon, Reddit, Twitch, Spotify, Discord, Zoom, Microsoft, Apple, Cloudflare, Akamai, plus generic HTTP/HTTPS/DNS.
- C++17 compiler (g++ β₯ 7 or clang++ β₯ 5)
- POSIX threads (
-pthread) for the MT engine - Python 3.8+ with
fastapi,uvicorn,python-multipartfor the web dashboard - No other external dependencies β PCAP parsing is built from scratch
MIT License β see LICENSE