This is the code:
package main
import (
"fmt"
"github.com/google/gopacket"
"github.com/google/gopacket/pcap"
)
func main() {
handle, err := pcap.OpenLive("\\Device\\NPF_{d6194530-0e27-4c84-b489-2cfe18d4af24}", 65536, true, pcap.BlockForever)
if err != nil {
fmt.Println(err)
}
defer handle.Close()
packets := gopacket.NewPacketSource(handle, handle.LinkType())
for packet := range packets.Packets() {
fmt.Println(packet)
}
}
I have a computer with network card monitoring enabled and windows, with wireshark or scapy (with monitor = True) I can sniff packets, but not with gopacket. I start to enable monitor mode with "wlanhelper "Wi-Fi" mode monitor" and it returns "Success", when I run the code there is no error whatsoever. Sniffing only works when I'm not in monitor mode or I'm sniffing the loopback. Apparently there is no function to enable monitor mode on gopacket like scapy, i don't know. help me pls
get me the solution for enable monitor mode in gopacket (windows)
Does calling (*InactiveHandle).SetRFMon with parameter true
work for you?
package main
import (
"fmt"
"github.com/google/gopacket"
"github.com/google/gopacket/pcap"
)
func main() {
inactive, err := pcap.NewInactiveHandle("\\Device\\NPF_{d6194530-0e27-4c84-b489-2cfe18d4af24}")
if err != nil {
panic(err)
}
defer inactive.CleanUp()
// Call various functions on inactive to set it up the way you'd like:
must(inactive.SetRFMon(true))
must(inactive.SetSnapLen(65536))
must(inactive.SetPromisc(true))
must(inactive.SetTimeout(pcap.BlockForever))
// Finally, create the actual handle by calling Activate:
handle, err := inactive.Activate() // after this, inactive is no longer valid
if err != nil {
panic(err)
}
defer handle.Close()
packets := gopacket.NewPacketSource(handle, handle.LinkType())
for packet := range packets.Packets() {
fmt.Println(packet)
}
}
func must(err error) {
if err != nil {
panic(err)
}
}