本篇文章主要是结合我之前面试的各种经历和实战开发中遇到的问题解决经验整理的,希望这篇《错误的 802.11 数据包捕获方法——gopacket》对你有很大帮助!欢迎收藏,分享给更多的需要的朋友学习~
这是代码:
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(使用monitor = true)我可以嗅探数据包,但不能使用gopacket。 我开始使用“wlanhelper“wi-fi”模式监视器”启用监视器模式,它返回“成功”,当我运行代码时没有任何错误。 嗅探仅在我不处于监视模式或嗅探环回时才起作用。 显然没有像 scapy 这样在 gopacket 上启用监视模式的功能,我不知道。 请帮助我
给我在gopacket(windows)中启用监控模式的解决方案
正确答案
是否调用(*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)
}
}
好了,本文到此结束,带大家了解了《错误的 802.11 数据包捕获方法——gopacket》,希望本文对你有所帮助!关注golang学习网公众号,给大家分享更多Golang知识!
本文内容来源于互联网,如有侵权请联系删除。
