2018-06-02 01:00:54 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"strings"
|
|
|
|
"syscall"
|
|
|
|
|
2019-02-28 16:24:29 +01:00
|
|
|
"github.com/bdlm/log"
|
2018-06-02 01:00:54 +02:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
2019-02-28 16:22:55 +01:00
|
|
|
"dev.sum7.eu/genofire/wifictld-analyzer/capture"
|
2018-06-02 01:00:54 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2019-03-08 05:57:00 +01:00
|
|
|
capture.DEBUG = debug
|
2018-06-03 20:37:52 +02:00
|
|
|
|
2019-03-08 05:57:00 +01:00
|
|
|
coll := capture.NewCollector(func(addr *net.UDPAddr, msg *capture.SocketMSG) (*capture.SocketMSG, error) {
|
2018-06-02 01:00:54 +02:00
|
|
|
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() {
|
2019-03-01 10:54:19 +01:00
|
|
|
RootCMD.AddCommand(dumpCmd)
|
2018-06-02 01:00:54 +02:00
|
|
|
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, "")
|
|
|
|
}
|