5 "fmt" 6 "log" 7 8 "github.com/google/gopacket" 9 "github.com/google/gopacket/pcap" 10 ) 11 12 func main() { 13 device := "eth0" 14 filter := "tcp and port 80" 15 16 handle, err := pcap.OpenLive( 17 device, int32(0xFFFF), true, pcap.BlockForever, 18 ) 19 if err != nil { 20 log.Fatal(err) 21 } 22 defer handle.Close() 23 if err := handle.SetBPFFilter(filter); err != nil { 24 log.Fatal(err) 25 } 26 27 packetSource := gopacket.NewPacketSource(handle, handle.LinkType()) 28 for packet := range packetSource.Packets() { 29 fmt.Printf(“%s\n", packet) 30 fmt.Printf("%s", hex.Dump(packet.Data())) 31 } 32 }