File tree Expand file tree Collapse file tree 1 file changed +25
-2
lines changed
Expand file tree Collapse file tree 1 file changed +25
-2
lines changed Original file line number Diff line number Diff line change 33"""
44import argparse
55
6+ import dpkt
7+ from construct .lib import containers
68
7- def parse_file (filepath : str ) -> None :
8- print (f"hello -> { filepath } " )
9+
10+ containers .setGlobalPrintFullStrings (True )
11+
12+
13+ def packet_filter (filepath ):
14+ with open (filepath , 'rb' ) as fh :
15+ for ts , buf in dpkt .pcap .Reader (fh ):
16+ eth = dpkt .ethernet .Ethernet (buf )
17+
18+ # Make sure the Ethernet data contains an IP packet
19+ if not isinstance (eth .data , dpkt .ip .IP ):
20+ continue
21+
22+ ip = eth .data
23+ if not isinstance (ip .data , dpkt .udp .UDP ):
24+ continue
25+
26+ yield (ip .data , ts )
27+
28+
29+ def parse_file (pcap_filepath : str ) -> None :
30+ for packet , timestamp in packet_filter (pcap_filepath ):
31+ print (packet , timestamp )
932
1033
1134def main ():
You can’t perform that action at this time.
0 commit comments