Open 0xMALVEE opened 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)
}
}