0

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)

ANDRVV
  • 7
  • 5

1 Answers1

0

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)
    }
}
Zeke Lu
  • 6,349
  • 1
  • 17
  • 23
  • it works, but i can't disable monitor mode from wlanhelper, can it be done by putting with gopacket? – ANDRVV May 22 '23 at 15:04
  • Sorry but I don't understand your question. Can you elaborate the question? – Zeke Lu May 22 '23 at 15:30
  • sorry but my english sucks, after sniffing in monitor mode i can't then turn off monitor mode from the code itself, how can i do? – ANDRVV May 22 '23 at 15:39
  • On Windows, the `pcap` package wraps either winpcap or npcap. winpcap does not support `rfmon`. So I think it's helpful to read the doc for npcap. https://npcap.com/guide/npcap-users-guide.html#npcap-feature-dot11-wireshark – Zeke Lu May 22 '23 at 16:36