Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Overview
- ========
- This small utility takes pcap file and generates go code with byte slices containing packet data.
- Example: Command
- ```bash
- go run main.go -o gen.go -prefix somePackets -f /path/to/capture.pcap -package main
- ```
- generates code in file `gen.go`:
- ```go
- package main
- //
- // This file is generated automatically. DO NOT EDIT.
- // Generated on 2020-05-01 18:26:04.419441164 +0500 +05 m=+0.006958750
- //
- import "time"
- import "github.com/google/gopacket"
- var somePackets = []struct {
- Data []byte
- gopacket.CaptureInfo
- }{
- //
- // Frame 1
- {
- []byte{
- //
- // Ethernet, off: 0, len: 14
- 0xF8, 0x6E, 0xEE, 0x8B, 0xA4, 0x26, 0x8C, 0x90,
- 0xD3, 0x1E, 0x65, 0x4C, 0x81, 0x00,
- //
- // Dot1Q, off: 14, len: 4
- 0x02, 0x59, 0x08, 0x00,
- //
- // IPv4, off: 18, len: 20
- 0x45, 0xC0, 0x00, 0xC2, 0x9D, 0x66, 0x00, 0x00,
- 0x3D, 0x11, 0x09, 0x36, 0x2E, 0xE3, 0xBD, 0x01,
- 0x2E, 0xE3, 0xBB, 0x07,
- //
- // UDP, off: 38, len: 8
- 0x08, 0x4B, 0x08, 0x4B, 0x00, 0xAE, 0x00, 0x00,
- //
- // ... other layers
- },
- gopacket.CaptureInfo{
- // 2019-06-07T21:07:39.420703+05:00
- Timestamp: time.Unix(1559923659, 420703000),
- CaptureLength: 95,
- Length: 95,
- },
- },
- //
- // Frame 2
- // ... other frames follow
- }
- ```
- You may then traverse resulting array, implement `gopacket.PacketDataSource` over it, etc.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement