Created
February 10, 2017 22:24
-
-
Save aeppert/f00f49bc1eef9f6eff5f7c656f5f47ed to your computer and use it in GitHub Desktop.
Count Packets in a PCAP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "flag" | |
| "fmt" | |
| "github.com/google/gopacket" | |
| "github.com/google/gopacket/pcap" | |
| "log" | |
| ) | |
| var ( | |
| pcapFile = flag.String("r", "", "Filename to read from") | |
| handle *pcap.Handle | |
| err error | |
| ) | |
| func main() { | |
| flag.Parse() | |
| packet_count = 0 | |
| // Open file instead of device | |
| handle, err = pcap.OpenOffline(*pcapFile) | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| defer handle.Close() | |
| packetSource := gopacket.NewPacketSource(handle, handle.LinkType()) | |
| for range packetSource.Packets() { | |
| packet_count++ | |
| } | |
| fmt.Printf("%d\n", packet_count) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment