Closed schollz closed 6 years ago
package main import ( "fmt" "log" "strings" "time" "github.com/google/gopacket" "github.com/google/gopacket/layers" "github.com/google/gopacket/pcap" ) var ( device string = "wlx98ded014a3a9" snapshot_len int32 = 1024 promiscuous bool = false err error timeout time.Duration = 3 * time.Second handle *pcap.Handle ) func main() { // Open device handle, err = pcap.OpenLive(device, snapshot_len, promiscuous, timeout) if err != nil { log.Fatal(err) } defer handle.Close() // Use the handle as a packet source to process all packets packetSource := gopacket.NewPacketSource(handle, handle.LinkType()) for packet := range packetSource.Packets() { // Process packet here // fmt.Println(packet.String()) address := "" rssi := 0 for _, layer := range packet.Layers() { if layer.LayerType() == layers.LayerTypeRadioTap { rt := layer.(*layers.RadioTap) rssi = int(rt.DBMAntennaSignal) } else if layer.LayerType() == layers.LayerTypeDot11 { dot11 := layer.(*layers.Dot11) addresses := []string{dot11.Address1.String(), dot11.Address2.String(), dot11.Address3.String(), dot11.Address4.String()} isOk := false tempAddress := "" for _, ad := range addresses { if strings.Contains(ad, "ff:ff") { isOk = true } else if len(ad) > 0 { tempAddress = ad } } if isOk { address = tempAddress } } } if address != "" && rssi != 0 { fmt.Println(time.Now(), address, rssi) } // break } }