mirror of
https://github.com/lcdr/utils.git
synced 2024-08-30 17:32:16 +00:00
Added find_packets, a script for finding matching packets within multiple .zip captures
This commit is contained in:
parent
d15b3a05a5
commit
4811452be4
20
find_packets.py
Normal file
20
find_packets.py
Normal file
@ -0,0 +1,20 @@
|
||||
import argparse
|
||||
import os
|
||||
import re
|
||||
import zipfile
|
||||
|
||||
def find_packets(capture_dir, pattern):
|
||||
zips = [os.path.join(dirpath, f) for dirpath, dirnames, files in os.walk(capture_dir) for f in files if f.endswith('.zip')]
|
||||
for zip_path in zips:
|
||||
with zipfile.ZipFile(zip_path) as zip:
|
||||
filenames = [i for i in zip.namelist() if re.search(pattern, i) is not None and "of" not in i]
|
||||
for filename in filenames:
|
||||
yield os.path.join(zip_path, filename), zip.read(filename)
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("capture_dir")
|
||||
parser.add_argument("pattern")
|
||||
args = parser.parse_args()
|
||||
for filename, data in find_packets(args.capture_dir, args.pattern):
|
||||
print(filename)
|
Loading…
Reference in New Issue
Block a user