65 lines
1.6 KiB
Go
65 lines
1.6 KiB
Go
package cmd
|
|
|
|
import (
|
|
"net"
|
|
"os"
|
|
"os/signal"
|
|
"strings"
|
|
"syscall"
|
|
|
|
"github.com/bdlm/log"
|
|
"github.com/spf13/cobra"
|
|
|
|
"dev.sum7.eu/genofire/wifictld-analyzer/capture"
|
|
"dev.sum7.eu/genofire/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)
|
|
|
|
var ifacesConfigs []*capture.IFaceConfig
|
|
for _, iface := range ifaces {
|
|
ifaceConfig := &capture.IFaceConfig{
|
|
InterfaceName: iface,
|
|
Port: port,
|
|
IPAddress: ipAddress,
|
|
}
|
|
ifacesConfigs = append(ifacesConfigs, ifaceConfig)
|
|
}
|
|
|
|
data.DEBUG = debug
|
|
|
|
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, "")
|
|
}
|