-
Notifications
You must be signed in to change notification settings - Fork 39
/
main.go
73 lines (63 loc) · 1.66 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
package main
import (
"encoding/json"
"flag"
"github.com/fatih/color"
"github.com/google/gopacket/pcap"
"io/ioutil"
"log"
"os"
)
type Config struct {
DeviceName string `json:"deviceName"`
PacketFilter []string `json:"packetFilter"`
AutoSavePcapFiles bool `json:"autoSavePcapFiles"`
}
var config *Config
var listDevice = flag.Bool("l", false, "List the network devices on this machine")
var ip = flag.String("ip", "", "Designate the network devices to capture by IP")
func main() {
bytes, err := ioutil.ReadFile("./config.json")
if err != nil {
log.Fatalln("Could not load ./config.json", err)
}
err = json.Unmarshal(bytes, &config)
if err != nil {
log.Fatalln("Could not load ./config.json", err)
}
for packet := range config.PacketFilter {
packetFilter[config.PacketFilter[packet]] = true
}
flag.Parse()
if *listDevice {
devices, err := pcap.FindAllDevs()
if err != nil {
log.Fatal(err)
}
log.Println(color.RedString("Name"), "\tDescription\t", color.CyanString("IP address"), "\tSubnet mask")
for _, device := range devices {
log.Println(color.RedString(device.Name), "\t", device.Description, "\t")
for _, address := range device.Addresses {
log.Println("\t\t\t", color.CyanString(address.IP.String()), "\t", address.Netmask)
}
}
os.Exit(0)
}
if len(*ip) > 0 {
devices, err := pcap.FindAllDevs()
if err != nil {
log.Fatal(err)
}
for _, device := range devices {
for _, address := range device.Addresses {
if address.IP.String() == *ip {
log.Println("Device ", device.Name, " is chose")
config.DeviceName = device.Name
break
}
}
}
}
go InitProto()
startServer()
}