-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathtcpdump2binary.py
More file actions
executable file
·36 lines (28 loc) · 1.16 KB
/
Copy pathtcpdump2binary.py
File metadata and controls
executable file
·36 lines (28 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/home/thanassis/bin/.scapy/bin/python3
import os
import argparse
from scapy.all import Ether, rdpcap
def extract_eth_payloads(tcpdump_file, output_dir):
os.makedirs(output_dir, exist_ok=True)
packets = rdpcap(tcpdump_file)
for i, packet in enumerate(packets):
if Ether in packet:
eth_header = bytes(packet[Ether])
filename = os.path.join(output_dir, f'frame_{i:06d}.bin')
with open(filename, 'wb') as f:
f.write(eth_header)
def main():
parser = argparse.ArgumentParser(
prog='tcpdump2binary',
description='Tcpdump capture to (many) binary ETH frames',
epilog='Uses scapy for the actual extraction.')
parser.add_argument('filename', help='filename containing tcpdump capture')
parser.add_argument('-o', '--outputFolder',
help='The folder to store the output ETH frames',
default='extractedFrames')
args = parser.parse_args()
tcpdump_file = args.filename
output_dir = args.outputFolder
extract_eth_payloads(tcpdump_file, output_dir)
if __name__ == "__main__":
main()