wifictld-analyzer/cmd/dump.go

65 lines
1.5 KiB
Go
Raw Normal View History

2018-06-02 01:00:54 +02:00
package cmd
import (
"net"
"os"
"os/signal"
"strings"
"syscall"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"dev.sum7.eu/wifictld/analyzer/capture"
"dev.sum7.eu/wifictld/analyzer/data"
)
var (
port int
ipAddress string
)
// queryCmd represents the query command
var dumpCmd = &cobra.Command{
Use: "dump <interfaces>",
Short: "capture wifictld traffic and just display the values (like wireshark)",
Example: `analyzer dump "eth0,wlan0"`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
ifaces := strings.Split(args[0], ",")
log.Infof("listen on: %s", ifaces)
2018-07-10 21:40:38 +02:00
var ifacesConfigs []*capture.IFaceConfig
2018-06-02 01:00:54 +02:00
for _, iface := range ifaces {
2018-07-10 21:40:38 +02:00
ifaceConfig := &capture.IFaceConfig{
2018-06-02 01:00:54 +02:00
InterfaceName: iface,
Port: port,
IPAddress: ipAddress,
}
ifacesConfigs = append(ifacesConfigs, ifaceConfig)
}
2018-06-03 20:37:52 +02:00
data.DEBUG = debug
2018-06-02 01:00:54 +02:00
coll := capture.NewCollector(func(addr *net.UDPAddr, msg *data.SocketMSG) (*data.SocketMSG, error) {
log.Infof("recv[%s]: %s", addr, msg.String())
return nil, nil
}, ifacesConfigs)
defer coll.Close()
// Wait for INT/TERM
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
sig := <-sigs
log.Println("received", sig)
},
}
func init() {
RootCmd.AddCommand(dumpCmd)
dumpCmd.Flags().IntVar(&port, "port", capture.Port, "define a port to listen (if not set or set to 0 the kernel will use a random free port at its own)")
dumpCmd.Flags().StringVar(&ipAddress, "listen", capture.MulticastAddressDefault, "")
}