Thanks to visit codestin.com
Credit goes to github.com

Skip to content

A comprehensive network packet analyzer that provides both a native CLI tool and a Model Context Protocol (MCP) server for deep analysis of PcapNG and PCAP network capture files.

Notifications You must be signed in to change notification settings

itsalfredakku/pcapng-analyzer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

PcapNG Analyzer

A comprehensive network packet analyzer that provides both a native CLI tool and a Model Context Protocol (MCP) server for deep analysis of PcapNG and PCAP network capture files.

🎯 Features

βœ… Dual Interface - Native CLI tool + MCP server for AI integration
βœ… Complete Packet Analysis - Deep protocol parsing with headers, payloads, and metadata
βœ… Network Flow Analysis - Track conversations, bandwidth usage, and connection patterns
βœ… Protocol Intelligence - Ethernet, IPv4, TCP/UDP parsing with application layer detection
βœ… Advanced Analytics - Timing analysis, protocol distribution, and traffic statistics
βœ… Multiple Formats - PcapNG, PCAP support with human-readable, JSON, and table outputs
βœ… Real-time Insights - Payload previews, packet flags, MAC addresses, and port analysis
βœ… Production Ready - High-performance Rust implementation with comprehensive error handling

πŸš€ Quick Start

Primary CLI Tool (pcapng-cli)

# Build CLI tool
cargo build --features cli --release

# Parse detailed packets with protocol analysis
./target/release/pcapng-cli packets capture.pcapng --limit 10 --payload

# Analyze network flows and conversations
./target/release/pcapng-cli flows capture.pcapng --sort-by-count

# Generate comprehensive traffic analysis
./target/release/pcapng-cli analyze capture.pcapng --protocols --timing

# Get file information
./target/release/pcapng-cli info capture.pcapng

# Multiple output formats
./target/release/pcapng-cli packets capture.pcapng --format json
./target/release/pcapng-cli flows capture.pcapng --format table

Advanced CLI Tool (pcapng-analyzer)

# Build advanced analyzer
cargo build --features cli --release

# Batch analysis of multiple files
./target/release/pcapng-analyzer batch --dir ./captures --summary

# Compare two capture files
./target/release/pcapng-analyzer compare file1.pcapng file2.pcapng --packets --timing

# Generate detailed statistics
./target/release/pcapng-analyzer stats capture.pcapng --protocols --detailed

MCP Server (AI Integration)

# Build MCP server
cargo build --features mcp-server --release

# Start MCP server (connects via stdio)
./target/release/pcapng-mcp-server

# Test MCP server manually
echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/list"}' | ./target/release/pcapng-mcp-server

MCP Client Integration

// Initialize MCP server
{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {}}

// List all available analysis tools
{"jsonrpc": "2.0", "id": 2, "method": "tools/list"}

// Parse detailed packets with protocol analysis
{"jsonrpc": "2.0", "id": 3, "method": "tools/call", "params": {
  "name": "parse_detailed_packets", 
  "arguments": {"file_path": "/path/to/capture.pcapng", "limit": 10}
}}

// Analyze network flows
{"jsonrpc": "2.0", "id": 4, "method": "tools/call", "params": {
  "name": "analyze_packet_flows", 
  "arguments": {"file_path": "/path/to/capture.pcapng"}
}}

πŸ› οΈ Analysis Tools Available

Primary CLI Commands (pcapng-cli)

Command Description Example
packets Deep packet analysis with protocol headers, payloads, and metadata pcapng-cli packets file.pcap --limit 5 --payload
flows Network flow analysis tracking conversations and bandwidth pcapng-cli flows file.pcap --sort-by-count
analyze Comprehensive traffic analytics with protocol distribution and timing pcapng-cli analyze file.pcap --protocols --timing
info Basic file information and metadata pcapng-cli info file.pcap
interfaces Network interface details pcapng-cli interfaces file.pcap
timing Packet timing analysis pcapng-cli timing file.pcap

Advanced CLI Commands (pcapng-analyzer)

Command Description Example
batch Multi-file analysis with summary reports pcapng-analyzer batch --dir ./captures --summary
compare File comparison with detailed diff analysis pcapng-analyzer compare file1.pcap file2.pcap --packets
stats Advanced statistics with protocol breakdown pcapng-analyzer stats file.pcap --protocols --detailed
validate File integrity and format validation pcapng-analyzer validate file.pcap
export Export to different formats (CSV, JSON, etc.) pcapng-analyzer export file.pcap --format csv

MCP Server Tools

Tool Description Capabilities
parse_detailed_packets Advanced packet parsing Ethernet/IP/TCP headers, payload preview, protocol stack
analyze_packet_flows Flow analysis and tracking Conversations, bandwidth, duration, connection patterns
generate_packet_analysis Comprehensive analytics Protocol distribution, timing analysis, packet statistics
parse_pcapng_file Basic file parsing File info, packet counts, interfaces
get_pcapng_metadata File metadata extraction Structure details, capture info
list_pcapng_interfaces Interface enumeration Network interface details

πŸ“‹ Detailed Packet Analysis Example

CLI Output Sample

$ ./target/release/pcapng-cli packets capture.pcapng --limit 3 --payload

πŸ“¦ Detailed Packet Analysis
===========================
πŸ“ File: capture.pcapng
πŸ“Š Total packets parsed: 3

πŸ“¦ Packet #1
   πŸ•’ Timestamp: 2025-08-01 11:40:21.351025 UTC
   πŸ“ Size: 42 bytes (captured: 42)
   πŸ”— Protocols: Ethernet
   πŸ–§  Ethernet: 00:ae:c8:9c:93:6b β†’ ea:03:a2:68:0f:96
   πŸ“„ Payload: Hex: 00 01 08 00 06 04 00 01... | ASCII: ................

πŸ“¦ Packet #2
   πŸ•’ Timestamp: 2025-08-01 11:40:21.337661 UTC
   πŸ“ Size: 345 bytes (captured: 345)
   πŸ”— Protocols: Ethernet β†’ IPv4 β†’ TCP
   πŸ–§  Ethernet: bc:24:11:c8:7d:65 β†’ c2:06:cc:7f:3f:fe
   🌐 IP: 62.24.65.220 β†’ 77.48.2.30 (TTL: 128, Protocol: TCP)
   πŸ”Œ TCP: 3389 β†’ 54591
   🏁 TCP Flags: ---PA---
   πŸ“„ Payload: Hex: 17 03 03 01 1e 00 00... | ASCII: ...............

MCP JSON Response Sample

{
  "packet_count": 1,
  "packets": [{
    "packet_number": 1,
    "timestamp": "2025-08-01T11:40:21.351025Z",
    "captured_length": 345,
    "original_length": 345,
    "protocols": ["Ethernet", "IPv4", "TCP"],
    "ethernet_header": {
      "source_mac": "bc:24:11:c8:7d:65",
      "destination_mac": "c2:06:cc:7f:3f:fe",
      "ethertype": 2048,
      "ethertype_name": "IPv4"
    },
    "ip_header": {
      "version": 4,
      "source_ip": "62.24.65.220",
      "destination_ip": "77.48.2.30",
      "protocol": 6,
      "protocol_name": "TCP",
      "ttl": 128,
      "header_length": 20
    },
    "transport_header": {
      "protocol": "TCP",
      "source_port": 3389,
      "destination_port": 54591,
      "tcp_flags": {
        "syn": false,
        "ack": true,
        "psh": true,
        "fin": false,
        "rst": false,
        "urg": false
      }
    },
    "payload_preview": "Hex: 17 03 03 01 1e 00... | ASCII: ..............."
  }]
}

🌊 Network Flow Analysis Example

CLI Flow Analysis

$ ./target/release/pcapng-cli flows capture.pcapng --sort-by-count

🌊 Network Flow Analysis
========================
πŸ“ File: capture.pcapng
πŸ“Š Total flows: 65

🌊 Flow: 62.24.65.220:3389 β†’ 77.48.2.30:54591 (TCP)
   πŸ“¦ Packets: 541
   πŸ“Š Bytes: 299,347
   ⏱️  Duration: 15.345s
   πŸ•’ First seen: 2025-08-01 11:40:21.337661 UTC
   πŸ•’ Last seen: 2025-08-01 11:40:36.682810 UTC

🌊 Flow: 77.48.2.3:51875 β†’ 62.24.65.220:443 (TCP)
   πŸ“¦ Packets: 121
   πŸ“Š Bytes: 45,876
   ⏱️  Duration: 7.473s

πŸ“Š Comprehensive Analytics Example

Protocol Distribution & Statistics

$ ./target/release/pcapng-cli analyze capture.pcapng --protocols --timing

πŸ“Š Comprehensive Packet Analysis
================================
πŸ“¦ Total packets: 2189

πŸ“‹ Protocol Distribution:
   Ethernet        2189     (100.0%)
   TCP             1568     (71.6%)
   IPv4            1620     (74.0%)
   UDP             52       (2.4%)

πŸ“ Packet Size Statistics:
   Min size: 42 bytes
   Max size: 1514 bytes
   Average size: 262.3 bytes

⏱️  Timing Analysis:
   Total duration: 15.438s
   Average PPS: 141.8
   Peak PPS: 892.5

πŸ’¬ Top Conversations:
   62.24.65.220 ↔ 77.48.2.30    1020 packets, 341,053 bytes
   77.48.2.3 ↔ 62.24.65.220     282 packets, 99,745 bytes

πŸ—οΈ Architecture

The PcapNG Analyzer employs a modular architecture designed for both standalone operation and MCP integration:

pcapng-analyzer/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ lib.rs              # Core library exports
β”‚   β”œβ”€β”€ pcapng/
β”‚   β”‚   β”œβ”€β”€ mod.rs          # PcapNG module root
β”‚   β”‚   β”œβ”€β”€ parser.rs       # Basic file parsing
β”‚   β”‚   β”œβ”€β”€ packet_parser.rs # Detailed packet analysis
β”‚   β”‚   β”œβ”€β”€ flow_analyzer.rs # Network flow tracking
β”‚   β”‚   └── types.rs        # Common data structures
β”‚   β”œβ”€β”€ mcp/
β”‚   β”‚   β”œβ”€β”€ mod.rs          # MCP module root
β”‚   β”‚   β”œβ”€β”€ server.rs       # JSON-RPC 2.0 server
β”‚   β”‚   └── client.rs       # MCP client utilities
β”‚   └── bin/
β”‚       β”œβ”€β”€ cli.rs          # Native CLI application
β”‚       └── mcp_server.rs   # MCP server binary
β”œβ”€β”€ Cargo.toml              # Multi-binary configuration
└── README.md

Key Components

πŸ”§ Core Parser (src/pcapng/)

  • Standards-compliant PcapNG file parsing
  • Protocol-aware packet dissection (Ethernet, IP, TCP, UDP)
  • Network flow reconstruction and analysis
  • Performance optimized for large captures

πŸ–₯️ CLI Interface (src/bin/cli.rs)

  • Direct command-line access to all analysis features
  • Multiple output formats (human-readable, JSON)
  • Batch processing capabilities
  • Real-time analysis feedback

πŸ”Œ MCP Server (src/mcp/server.rs)

  • JSON-RPC 2.0 compliant implementation
  • Six specialized analysis tools
  • Seamless integration with MCP-compatible clients
  • Structured data output for programmatic access

βš™οΈ Build System

  • Feature-gated compilation (cli, mcp-server)
  • Conditional dependencies for optimized builds
  • Release builds for production deployment

οΏ½ Getting Started

Quick Analysis Demo

# Clone and build
git clone https://github.com/your-org/pcapng-analyzer
cd pcapng-analyzer
cargo build --release --features cli

# Analyze a capture file
./target/release/pcapng-cli analyze demo.pcapng --protocols --timing

# Extract detailed packets
./target/release/pcapng-cli packets demo.pcapng --limit 10 --payload

MCP Integration Demo

# Start MCP server
./target/release/pcapng-mcp-server

# In MCP client, available tools:
# - parse_pcapng_file
# - get_pcapng_metadata  
# - list_pcapng_interfaces
# - parse_detailed_packets
# - analyze_packet_flows
# - generate_packet_analysis

οΏ½πŸ“Š Tested With Real Files

Successfully tested with multiple real-world PcapNG files:

  • βœ… 974 packets (19 second capture, 211KB file)
  • βœ… 2189 packets (15 second capture, 647KB file, 2 interfaces)
  • βœ… 282 packets (8 second capture, 109KB file, 2 interfaces)
  • βœ… Various network protocols and interface configurations

πŸ”§ Dependencies

  • Rust - Async/await, error handling, performance
  • rmcp - Model Context Protocol implementation
  • pcap-parser - Low-level packet parsing
  • serde - JSON serialization
  • tokio - Async runtime

🀝 Contributing

We welcome contributions! Whether you're fixing bugs, adding features, or improving documentation:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Setup

git clone https://github.com/your-org/pcapng-analyzer
cd pcapng-analyzer
cargo build --all-features
cargo test

πŸ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • pcap-parser - Robust PcapNG parsing foundation
  • rmcp - Model Context Protocol implementation
  • The network analysis community for inspiration and standards

Built with ❀️ for network analysis and automation

⭐ Star this repo β€’ πŸ› Report Issues β€’ πŸ’‘ Request Features

About

A comprehensive network packet analyzer that provides both a native CLI tool and a Model Context Protocol (MCP) server for deep analysis of PcapNG and PCAP network capture files.

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

  •  

Packages

No packages published

Languages