-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
89 lines (82 loc) · 2.08 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
86
87
88
89
package main
import (
_ "fmt"
"os"
"github.com/codegangsta/cli"
"github.com/cxfksword/httpcap/common"
"github.com/cxfksword/httpcap/config"
)
func main() {
app := cli.NewApp()
app.Name = "httpcap"
app.Usage = "A simple network analyzer that capture http network traffic."
app.Version = "0.1.0"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "interface, i",
Value: "",
Usage: "interface to listen on (e.g. eth0, en1, or 192.168.1.1, 127.0.0.1 etc.)",
},
cli.StringFlag{
Name: "port, p",
Value: "",
Usage: "port to listen on (default listen on all port)",
},
cli.BoolFlag{
Name: "raw, r",
Usage: "show raw stream. it is a shortcut for -l %request%response",
},
cli.StringFlag{
Name: "format, f",
Value: "",
Usage: "output format. You can specify the output string format containing reserved keyword that will be replaced with the proper value",
},
cli.StringFlag{
Name: "keyword, k",
Value: "",
Usage: "filte output with the keyword in request url",
},
cli.IntFlag{
Name: "body, b",
Value: 0,
Usage: "the length to truncate response body (0 - not show body, -1 - show all body)",
},
cli.StringFlag{
Name: "service, s",
Value: "http",
Usage: "limit output service (http|memcache|redis|mongodb|twemproxy|mysql)",
},
cli.BoolFlag{
Name: "verbose, vv",
Usage: "output debug message",
},
}
app.Commands = []cli.Command{
{
Name: "list",
Usage: "show all interfaces",
Action: func(c *cli.Context) {
common.ShowAllInterfaces()
},
}}
app.Action = func(c *cli.Context) {
config.Setting.Verbose = c.Bool("verbose")
config.Setting.InterfaceName = c.String("interface")
config.Setting.Port = c.String("port")
config.Setting.Format = c.String("format")
config.Setting.Filter = c.String("keyword")
config.Setting.TruncateBodyLength = c.Int("body")
config.Setting.Raw = c.Bool("raw")
config.Setting.Service = c.String("service")
if c.Bool("version") {
cli.ShowVersion(c)
return
}
if c.Bool("help") {
cli.ShowAppHelp(c)
return
}
startCapture()
}
app.Run(os.Args)
}