-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
85 lines (72 loc) · 2.26 KB
/
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
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
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
"fmt"
"os"
flag "github.com/bugwz/go-flag"
s "github.com/bugwz/hamburg/src"
)
var version = "1.0"
var (
snaplen int
slow, count, duration int64
interfile, outfile, fips, fports, protocol, script, fcustom string
showreply, help bool
)
func usage() {
fmt.Fprintf(os.Stderr, `
_ _
| |__ __ _ _ __ ___ | |__ _ _ _ __ __ _
| '_ \ / _' | '_' '_ \| '_ \| | | | '__/ _| |
| | | | (_| | | | | | | |_) | |_| | | | (_| |
|_| |_|\__,_|_| |_| |_|_.__/ \__,_|_| \__, |
|___/ `+version+`
A tool to capture data packets and time-consuming analysis.
Options:
`)
flag.PrintDefaults()
}
func init() {
flag.StringVar(&interfile, "i", "", "monitor network interface or offline pcap file")
flag.StringVar(&outfile, "o", "", "outfile for the captured package")
flag.StringVar(&fips, "s", "", "filtered ip list, splited with commas")
flag.StringVar(&fports, "p", "", "filtered port list, splited with commas")
flag.StringVar(&protocol, "m", "raw", "packet protocol type with raw/dns/http/redis/memcached/mysql")
flag.Int64Var(&slow, "t", 1, "threshold for slow requests (millisecond)")
flag.Int64Var(&duration, "d", 0, "running time for capturing packets (second), (default unlimited)")
flag.StringVar(&script, "x", "", "lua script file")
flag.IntVar(&snaplen, "n", 1500, "maximum length of the captured data packet snaplen")
flag.StringVar(&fcustom, "e", "", "customized packet filter")
flag.BoolVar(&showreply, "a", false, "show the contents of the reply packet (default false)")
flag.BoolVar(&help, "h", false, "help")
flag.SetSortFlags(false)
flag.Usage = usage
}
func setconf(c *s.Conf) {
c.InterFile = interfile
c.Outfile = outfile
c.FilterIPs = fips
c.FilterPorts = fports
c.Protocol = protocol
c.SlowThreshold = slow
c.Duration = duration
c.SnapLen = snaplen
c.Script = script
c.FilterCustom = fcustom
c.ShowReply = showreply
}
func main() {
c := s.NewConf()
flag.Parse()
if help {
flag.Usage()
return
}
setconf(c)
h, e := s.NewHamburg(c)
if e != nil {
fmt.Println(e)
return
}
h.Run()
return
}