-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathgopacket.example.go
More file actions
28 lines (24 loc) · 830 Bytes
/
Copy pathgopacket.example.go
File metadata and controls
28 lines (24 loc) · 830 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package main
import (
"github.com/bettercap/bettercap/log"
"github.com/chifflier/nfqueue-go/nfqueue"
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
)
func OnPacket(payload *nfqueue.Payload) int {
packet := gopacket.NewPacket(payload.Data, layers.LayerTypeIPv4, gopacket.Default)
log.Info("%s", packet.Dump())
payload.SetVerdict(nfqueue.NF_ACCEPT)
return 0
}
// Get packets from some source
for packet := range someSource {
if app := packet.ApplicationLayer(); app != nil {
if strings.Contains(string(app.Payload()), "magic string") {
fmt.Println("Found magic string in a packet!")
}
}
packet := gopacket.NewPacket(myPacketData, layers.LayerTypeEthernet, gopacket.Default)
if err := packet.ErrorLayer(); err != nil {
fmt.Println("Error decoding some part of the packet:", err)
}