-
Notifications
You must be signed in to change notification settings - Fork 14
/
qisniff.go
72 lines (59 loc) · 1.44 KB
/
qisniff.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
qisniff tries to assemble incoming tcp streams, and will warn you if any one of them contained packets
with different payloads for the same segment of the stream.
Usage:
go get github.com/zond/qisniff
qisniff -file=file.pcap
qisniff -dev=en0
*/
package main
import (
"flag"
"fmt"
"log"
"os"
"github.com/google/gopacket"
"github.com/google/gopacket/pcap"
"github.com/zond/qisniff/qilib"
)
func main() {
file := flag.String("file", "", "A file to parse")
dev := flag.String("dev", "", "A dev to sniff")
flag.Parse()
if (*file == "" && *dev == "") || (*file != "" && *dev != "") {
flag.Usage()
os.Exit(1)
}
var handle *pcap.Handle
var err error
// Open the pcap file or device.
if *file != "" {
if handle, err = pcap.OpenOffline(*file); err != nil {
panic(err)
}
} else {
if handle, err = pcap.OpenLive(*dev, 8196, true, pcap.BlockForever); err != nil {
panic(err)
}
}
count := 0
bars := []string{"-", "\\", "|", "/"}
sess := qilib.NewSession(qilib.Config{
Handle: handle,
Progress: func(pkt gopacket.Packet) {
fmt.Printf("\r%v ", bars[count%len(bars)])
count++
},
Warning: func(pkt gopacket.Packet, diff qilib.Diff) {
fmt.Printf("\n%v %v\n<A>\n%s\n</A>\n<B>\n%s\n</B>\n", diff.ID, diff.Seq, diff.A, diff.B)
},
Unparseable: func(pkt gopacket.Packet) {
fmt.Printf("\nUnparseable packet\n%v\n", pkt)
},
})
defer sess.Clean()
if err := sess.Run(); err != nil {
log.Fatal(err)
}
fmt.Println()
}