Browse Source

adding filter possiblity

master
Christopher Talib 2 years ago
parent
commit
25ed2fc961
  1. 16
      main.go

16
main.go

@ -12,15 +12,21 @@ import (
"github.com/google/gopacket/pcapgo"
)
// Handle is a local wrapper around pcap.Handle structure.
type Handle struct {
handle *pcap.Handle
}
func main() {
// find devices and return them
devices := findDevices()
filterExpression := "tcp and port 80"
// try to capture on devices
for _, d := range devices {
fmt.Println("trying: ", d.Name)
fmt.Println("trying:", d.Name)
err := openDeviceForCapture(d.Name)
err := openDeviceForCapture(d.Name, filterExpression)
if err != nil {
fmt.Println(err)
}
@ -37,7 +43,7 @@ func pcapName(deviceName string) *os.File {
}
func openDeviceForCapture(deviceName string) error {
func openDeviceForCapture(deviceName string, filterExpression string) error {
var snapshotLen int32
snapshotLen = 1024
promiscuous := false
@ -49,6 +55,10 @@ func openDeviceForCapture(deviceName string) error {
if err != nil {
return err
}
// set filter to handle
if err := handle.SetBPFFilter(filterExpression); err != nil {
return err
}
defer handle.Close()
pcapName := pcapName(deviceName)

Loading…
Cancel
Save