802.11 packet sniffing errors on Windows - gopacket

WBOY
Release: 2024-02-08 22:00:36
forward
1184 people have browsed it

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

php小编百草为大家带来了关于Windows上的802.11数据包嗅探错误的解决方法。在使用gopacket进行数据包嗅探时,可能会遇到一些问题。本文将针对这些问题进行详细的分析和解决方案的介绍,帮助读者更好地进行数据包嗅探工作。无论是初学者还是有经验的开发者,都可以从本文中获得有用的技巧和知识,提高在Windows上进行数据包嗅探的效率和准确性。

问题内容

这是代码:

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)
    }
}
Copy after login

我有一台启用了网卡监控的计算机和windows,使用wireshark或scapy(使用monitor = true)我可以嗅探数据包,但不能使用gopacket。 我开始使用“wlanhelper“wi-fi”模式监视器”启用监视器模式,它返回“成功”,当我运行代码时没有任何错误。 嗅探仅在我不处于监视模式或嗅探环回时才起作用。 显然没有像 scapy 这样在 gopacket 上启用监视模式的功能,我不知道。 请帮助我

给我在gopacketwindows)中启用监控模式的解决方案

解决方法

是否调用(*inactivehandle)。 setrfmon 参数 true 适合你吗?

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)
    }
}
Copy after login

The above is the detailed content of 802.11 packet sniffing errors on Windows - gopacket. For more information, please follow other related articles on the PHP Chinese website!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template