Windows上的错误802.11数据包嗅探- gopacket

hgc7kmma  于 2023-05-27  发布在  Go
关注(0)|答案(1)|浏览(150)

代码如下:

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)
    }
}

我有一台启用了网卡监控和windows的电脑,用wireshark或scapy(with monitor = True)我可以嗅探数据包,但用gopacket不行。我开始启用监视器模式与“wlanhelper“Wi-Fi”模式监视器”,它返回“成功”,当我运行代码没有任何错误.嗅探只在我不处于监视模式或嗅探环回时起作用。显然,没有功能,以启用监视器模式的gopacket像scapy,我不知道。帮帮我
获取在gopacketwindows)中启用monitor模式的解决方案

i5desfxk

i5desfxk1#

使用参数true调用(*InactiveHandle).SetRFMon是否有效?

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)
    }
}

相关问题