diff --git a/main.go b/main.go index 0a7a15b..57297c4 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,7 @@ import ( "os/exec" "runtime" "strings" + "time" "strconv" @@ -70,12 +71,21 @@ func sInit(os string) *targetInfo { return &tInfo } +func openCapture(tInfo *targetInfo) *pcap.Handle { + for { + handle, err := pcap.OpenLive(tInfo.iFace, tInfo.snaplen, true, pcap.BlockForever) + if err == nil { + return handle + } + time.Sleep(5 * time.Second) + } +} + func main() { tInfo := sInit(runtime.GOOS) // Read package and analze them - handle, err := pcap.OpenLive(tInfo.iFace, tInfo.snaplen, true, pcap.BlockForever) - errorPrinter(err) + handle := openCapture(tInfo) handle.SetBPFFilter(tInfo.filter) packets := gopacket.NewPacketSource(handle, handle.LinkType()).Packets()