# capture_packet **Repository Path**: foxchenlei/capture_packet ## Basic Information - **Project Name**: capture_packet - **Description**: golang简单的进行抓包 - **Primary Language**: Go - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-12-11 - **Last Updated**: 2024-12-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Network Packet Capture Tool A Go-based network packet capture tool that monitors and displays HTTP and HTTPS traffic details. The tool uses TCP stream reassembly to properly reconstruct HTTP requests and detect HTTPS connections. ## Features - Captures and displays both HTTP and HTTPS traffic in real-time - Shows complete URI and Host information for HTTP requests - Detects and reports HTTPS connections - Supports filtering by source/destination IP and ports - Works with HTTP/HTTPS traffic on any port (not limited to 80/443) - TCP stream reassembly for accurate traffic analysis - Easy-to-use command-line interface ## Prerequisites - Go 1.x or higher - libpcap development files - For Windows: WinPcap or Npcap - For Linux: `libpcap-dev` ## Installation ```bash go mod download ``` ## Usage Basic usage: ```bash go run main.go -i ``` ### Command Line Parameters - `-i`: Network interface name (required) - `-sip`: Filter by source IP address - `-dip`: Filter by destination IP address - `-sport`: Filter by source port - `-dport`: Filter by destination port ### Examples 1. List available network interfaces: ```bash go run main.go ``` 2. Capture all HTTP/HTTPS traffic on a specific interface: ```bash go run main.go -i eth0 ``` 3. Filter traffic from a specific source IP: ```bash go run main.go -i eth0 -sip 192.168.1.100 ``` 4. Filter traffic to a specific destination port: ```bash go run main.go -i eth0 -dport 443 ``` 5. Combine multiple filters: ```bash go run main.go -i eth0 -sip 192.168.1.100 -dport 80 ``` ## Output Format ### For HTTP Requests: ``` HTTP Connection: Source IP: 192.168.1.100 Destination IP: 93.184.216.34 Source Port: 54321 Destination Port: 8080 Protocol: HTTP Method: GET URI: /api/v1/data Host: example.com ---------------- ``` ### For HTTPS Connections: ``` HTTPS Connection: Source IP: 192.168.1.100 Destination IP: 93.184.216.34 Source Port: 54321 Destination Port: 443 Protocol: HTTPS (TLS) ---------------- ``` Note: For HTTPS connections, only connection information is shown as the content is encrypted. ## Dependencies - github.com/google/gopacket: Packet capturing and processing - github.com/google/gopacket/pcap: PCap library integration - github.com/google/gopacket/tcpassembly: TCP stream reassembly ## Note Running this tool requires administrative/root privileges to capture network traffic.