-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_me.py
More file actions
37 lines (32 loc) · 934 Bytes
/
run_me.py
File metadata and controls
37 lines (32 loc) · 934 Bytes
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
37
#!/usr/bin/env python
##
# Fix Path
import __init__
##
# Python Imports
import os
import sys
import binascii
##
# Project Imports
from header_pcap import PCAP_Header
from packet import Packet
##
# Global Variables
if __name__ == "__main__":
# Read the pcap file as binary data
with open(sys.argv[1], "rb") as file:
raw_bytes = file.read()
# PCAP Header
(pcap_header, raw_bytes) = PCAP_Header.parse_PCAP_Header(raw_bytes)
packets = []
while len(raw_bytes) != 0:
(packet, raw_bytes) = Packet.parse_Packet(pcap_header, raw_bytes)
packets.append(packet)
# Re-Write decapsulated packets
decap_bytes = pcap_header.raw_bytes
for packet in packets:
decap_bytes += packet.decapsulate()
filepath = os.path.join(os.path.dirname(sys.argv[1]), "decap_" + os.path.basename(sys.argv[1]))
with open(filepath, "wb") as file:
file.write(decap_bytes)