How hhhweihan/easytshark works
Project type and purpose
• EasyTshark is a standalone, command-line network packet capture and analysis tool (not a web app).
• It provides two modes:
• Real-time capture (from a network interface via tshark)
• Offline analysis (from an existing PCAP file)
• It stores packet metadata in a local SQLite database, performs XML/JSON conversions, and enriches data with IP geolocation via ip2region.
File structure
Top-level directories and files:
• run.sh, CMakeLists.txt → build & test orchestration
• / → headers for core modules and bundled third-party libs (loguru, rapidjson, rapidxml, ip2region)
• src/ → implementation of main, TsharkManager, utils, XDB search and benchmark
• output/ → compiled binaries (tshark_main, unit_tests)
• tests/ → Google Test suites
• data/ & logs/ → runtime outputs (packets.pcap, packets.db, packets.xml, packets.json, logs)
README for additional insights
• Dependencies: tshark, sqlite3, C++11, CMake
• Core features: dual capture modes, SQLite storage, XML ↔ JSON conversion, IP geolocation
• Testing: Google Test covers various modules (manager, utils, DB, conversion, error handling, integration)
Main components and their interactions
A. User CLI (Console)
• Presents mode selection menu (real-time vs offline)
• Collects parameters (interface name, duration, PCAP path)
→ invokes TsharkManager
B. TsharkManager
• Spawns tshark process (via ProcessUtil) → writes PCAP to working dir
• Parses PCAP metadata (tsharkDataType)
• Calls SQLiteUtil to create/open database and insert packet records
• Calls XMLConverter (rapidxml) to generate packets.xml
• Calls JSONConverter (rapidjson) to generate packets.json
• Calls IP2RegionUtil to enrich each packet’s IP
C. Storage Layer (SQLite)
• packets.db holds raw packet metadata for querying
D. Conversion Modules
• PCAP→XML (rapidxml)
• XML→JSON (rapidjson)
E. IP Geolocation
• ip2region.xdb lookup per IP address
F. Logging
• loguru records every operational step, errors, and performance metrics
G. Output files
• data/capture.pcap, packets.db, packets.xml, packets.json
• logs/…
H. Build & Test
• CMake & run.sh orchestrate compilation and Google Test execution
• Unit & integration tests ensure correctness of each module
Architectural patterns and principles
• Modular separation: manager, storage, conversion, util modules
• Single Responsibility: each converter and util has one domain
• Layered architecture: CLI → orchestration → processing → storage → output
• Dependency injection via headers and CMake targets