A C++ console application for live network packet capture and protocol analysis on Windows. It uses Npcap to sniff traffic from a selected network interface, classifies IPv4 packets by protocol, and displays real-time statistics in the terminal.
- Live packet capture — Select a network adapter and capture traffic in real time
- Protocol classification — Parses Ethernet and IPv4 headers; counts TCP, UDP, ICMP, and other packets
- Real-time dashboard — Console UI with runtime metrics, protocol distribution bars, and an ASCII bandwidth graph
- Demo mode — Run without a network adapter using simulated traffic to preview the visualization
- The application lists available network devices via
pcap_findalldevs. - You choose an interface to monitor.
PacketCaptureopens the device withpcap_open_liveand processes each frame in a capture loop.- Each packet is parsed at the Ethernet and IP layers; the IP protocol field drives TCP/UDP/ICMP classification.
- Every 10 packets,
NetworkVisualizerrefreshes the terminal with updated metrics and charts. - Press Ctrl+C to stop capture and view final statistics.
Network-Protocol-Analyzer/
├── CMakeLists.txt
├── include/
│ ├── PacketCapture.h # Capture engine and PacketStats
│ └── NetworkVisualizer.h # Terminal dashboard and charts
└── src/
├── main.cpp # Device selection and live capture entry point
├── PacketCapture.cpp # Packet parsing and statistics
├── NetworkVisualizer.cpp # Real-time console visualization
└── demo.cpp # Simulated traffic demo (Demo target)
| Component | Technology |
|---|---|
| Language | C++17 |
| Build system | CMake 3.10+ |
| Packet capture | Npcap SDK (libpcap-compatible API) |
| Platform | Windows (Npcap, Winsock2) |
-
Npcap — Install the Npcap driver (not WinPcap). During setup, enable WinPcap API-compatible Mode if prompted.
-
Npcap SDK — Download the Npcap SDK and extract it. The default CMake configuration expects it at:
C:/npcap-sdk-1.15/If your SDK is elsewhere, update the
include_directoriesandlink_directoriespaths inCMakeLists.txt. -
CMake and a C++17 compiler (Visual Studio 2019+ recommended on Windows).
Note: Live packet capture requires running the executable as Administrator.
From the project root:
cmake -S . -B build
cmake --build build --config ReleaseBinaries are written to:
build/Release/NetworkProtocolAnalyzer.exe
build/Release/Demo.exe
For Debug builds, use --config Debug and look under build/Debug/.
Run as Administrator:
.\build\Release\NetworkProtocolAnalyzer.exe- Select a network device from the numbered list.
- Watch the real-time dashboard update as packets are captured.
- Press Ctrl+C to stop and print final statistics.
No admin rights or network adapter required:
.\build\Release\Demo.exeThis generates simulated TCP/UDP/ICMP traffic and drives the same dashboard used in live capture.
The terminal UI includes:
- Network metrics — Total packets, packets/sec, average packet size, bandwidth (bps)
- Protocol distribution — Percentage bars for TCP, UDP, ICMP, and other traffic
- Bandwidth history — ASCII chart of recent bytes/sec measurements
- Windows-only (Npcap/Winsock dependencies)
- IPv4 over Ethernet only; IPv6 and non-Ethernet frames are counted as Other
- No packet logging or pcap file export
- Npcap SDK path is hardcoded in
CMakeLists.txt
- Configurable Npcap SDK path via CMake variable or environment variable
- IPv6 and additional link-layer support
- Export capture statistics to CSV or JSON
- Optional pcap file input mode for offline analysis
- Cross-platform support (libpcap on Linux/macOS)
- Unit tests for packet parsing logic
This project is licensed under the MIT License. You are free to use, modify, and distribute the code with attribution.