Prepare
- install gopacket
go get github.com/google/gopacket/pcap
Install gcc
tohttp://tdm-gcc.tdragon.net/download
download gcc, configure gcc will not go into detailsInstall
winpcap
andwinpcap develop package
go tohttps://www.winpcap.org/devel.htm
download winpacp4.1.3 and development package 4.1.2 (there is no development package for 4.1.3)
Unzip WpdPack_4_1_2.zip to C:\WpdPack, this directory is necessary, otherwise the code in the go library must be modified
test
The function of this code is to display all network card device information of this device
package main
import (
"fmt"
"log"
"github.com/google/gopacket/pcap"
)
func main() {
// Find all devices
devices, err := pcap.FindAllDevs()
if err != nil {
log.Fatal(err)
}
// Print device information
fmt.Println("Devices found:")
for _, d := range devices {
fmt.Println("\nName: ", d.Name)
fmt.Println("Description: ", d.Description)
fmt.Println("Devices addresses: ", d.Description)
for _, address := range d.Addresses {
fmt.Println("- IP address: ", address.IP)
fmt.Println("- Subnet mask: ", address.Netmask)
}
}
}
go run test.go
warn
Don't go to this place to download the development package, https://www.winpcap.org/archive/ , I don't understand the version in it, and it's wrong to download several.
quote
https://blog.csdn.net/worldzhy/article/details/8234584
https://www.devdungeon.com/content/packet-capture-injection-and-analysis-gopacket
https://www.winpcap.org/devel.htm
https://godoc.org/github.com/google/gopacket