google / gopacket

Provides packet processing capabilities for Go
BSD 3-Clause "New" or "Revised" License
6.35k stars 1.13k forks source link

couldn't load wpcap.dll exit status 1 #1170

Open 0xMALVEE opened 6 months ago

0xMALVEE commented 6 months ago
M Alvee@DESKTOP-E1SNL1U MINGW64 ~/Documents/GitHub/GoNetCapture (main)
$ go run .
2024/05/21 16:55:58 couldn't load wpcap.dll
exit status 1
0xMALVEE commented 6 months ago

the go code

package main

import (
    "fmt"
    "log"

    "github.com/google/gopacket"
    "github.com/google/gopacket/pcap"
)

func main() {
    // Find all available network interfaces
    devices, err := pcap.FindAllDevs()
    if err != nil {
        log.Fatal(err)
    }

    // Choose the first network interface
    device := devices[0]

    // Open device for capturing
    handle, err := pcap.OpenLive(device.Name, 1600, true, pcap.BlockForever)
    if err != nil {
        log.Fatal(err)
    }
    defer handle.Close()

    // Set filter to capture only TCP packets
    err = handle.SetBPFFilter("tcp")
    if err != nil {
        log.Fatal(err)
    }

    // Start capturing packets
    packetSource := gopacket.NewPacketSource(handle, handle.LinkType())
    for packet := range packetSource.Packets() {
        // Do something with the captured packet
        fmt.Println(packet)
    }
}