A Deep Packet Inspection (DPI) engine written in C++ that analyzes network traffic from PCAP files, identifies applications using packet metadata and TLS SNI inspection, and applies filtering rules to block specific applications, domains, or IP addresses.
The system parses multiple network protocol layers, tracks connections using the Five-Tuple, and processes packets using a multi-threaded architecture to improve performance and scalability.
This project demonstrates how modern network monitoring and security systems analyze traffic beyond traditional packet filtering.
Captured network traffic is provided as a PCAP file, which is processed by the DPI engine. The engine analyzes each packet, applies filtering rules, and writes allowed traffic into a new filtered PCAP output file.
Input PCAP โ DPI Engine โ Filtered PCAP Output
- ๐ฆ Packet parsing
- ๐ Flow identification
- ๐ง Application detection
- ๐ซ Rule-based filtering
- ๐ Traffic statistics generation
The engine parses multiple network protocol layers:
- Ethernet
- IPv4
- TCP / UDP
- Application payload
This enables extraction of critical network metadata for deeper inspection.
Each connection is tracked using the Five-Tuple:
- ๐ Source IP address
- ๐ Destination IP address
- ๐ Source port
- ๐ Destination port
- ๐ก Protocol
Packets sharing the same Five-Tuple belong to the same network flow, allowing stateful traffic analysis.
The engine inspects packet payloads to detect applications.
For HTTPS traffic, it extracts the Server Name Indication (SNI) from the TLS handshake.
SNI reveals the domain name being accessed before encryption begins.
SNI: www.youtube.com
Detected Application: YouTube
The system supports rule-based traffic filtering, allowing blocking by:
- ๐งพ IP address
- ๐ฑ Application type
- ๐ Domain name
Packets matching blocking rules are dropped and not written to the output file.
The project includes two implementations.
A simple implementation where packets are processed sequentially.
Useful for:
- Learning packet inspection
- Debugging packet processing
PCAP Reader โ Packet Parser โ Classifier โ Rule Engine โ Output
A high-performance implementation that processes packets in parallel.
- ๐ฅ Reader thread โ Reads packets from PCAP
- โ๏ธ Load balancer threads โ Distribute packets
- โ๏ธ Worker threads (Fast Path) โ Process packets
- ๐พ Output writer thread โ Writes filtered packets
Reader โ Load Balancer โ Worker Threads โ Output Writer
This architecture allows the system to scale with available CPU cores.
deep-packet-inspector
โ
โโโ include/
โ Header files for packet parsing, flow tracking, and DPI logic
โ
โโโ src/
โ Core implementation of the DPI engine
โ
โโโ generate_test_pcap.py
โ Script used to generate sample network traffic
โ
โโโ test_dpi.pcap
โ Example PCAP file used for testing
โ
โโโ CMakeLists.txt
โ Build configuration file
โ
โโโ WINDOWS_SETUP.md
โ Windows build instructions
โ
โโโ README.md
Packets pass through several stages during analysis.
Packets are sequentially read from the PCAP file.
Network headers are parsed to extract:
- MAC addresses
- IP addresses
- Ports
- Protocol type
The system generates a Five-Tuple to track each connection.
For HTTPS packets, the TLS handshake is inspected to extract the SNI hostname.
Blocking rules are checked against the connection.
- โ Allowed packets โ written to output PCAP
- โ Blocked packets โ dropped
- C++17 compatible compiler
- Linux / macOS / Windows (MinGW)
- Python (optional, for generating test PCAP)
Example build command:
g++ -std=c++17 -O2 -I include \
src/*.cpp \
-o dpi_engine
./dpi_engine input.pcap output.pcap
./dpi_engine input.pcap output.pcap \
--block-app YouTube \
--block-ip 192.168.1.50 \
--block-domain facebook
Total Packets: 77
Forwarded: 69
Dropped: 8
Detected Applications:
HTTPS
YouTube
Facebook
DNS
The output displays traffic statistics and application detection results.
Possible enhancements include:
- โ Adding more application signatures
- ๐ก Supporting live network packet capture
- โฑ Implementing bandwidth throttling
- ๐ Creating a web dashboard for monitoring
- โก Adding support for QUIC / HTTP3 traffic
This project demonstrates important network security and packet analysis concepts:
- ๐ฆ Network packet structure
- ๐ Flow tracking using Five-Tuple
- ๐ Deep packet inspection techniques
- ๐ TLS handshake analysis
- โก Multi-threaded packet processing
It serves as a practical learning project for:
Network Security โข Packet Analysis โข Traffic Monitoring Systems