forked from google/gopacket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (41 loc) · 979 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright 2019 The GoPacket Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file in the root of the source
// tree.
// snoopread is a example for read a snoop file using
// gopacket and its subpackages and output the decoded data with a package count
package main
import (
"fmt"
"log"
"os"
"github.com/google/gopacket"
"github.com/google/gopacket/pcapgo"
)
func main() {
//download snoop from https://wiki.wireshark.org/SampleCaptures
f, err := os.Open("example.snoop")
if err != nil {
log.Fatal(err)
return
}
defer f.Close()
handle, err := pcapgo.NewSnoopReader(f)
if err != nil {
log.Fatal(err)
return
}
lt, err := handle.LinkType()
if err != nil {
log.Fatal(err)
return
}
packetSource := gopacket.NewPacketSource(handle, lt)
cnt := 0
for packet := range packetSource.Packets() {
fmt.Println(packet)
cnt++
}
fmt.Printf("Packet count: %d\n", cnt)
}