The script pcap_layer_analysis.py analyzes a PCAP/PCAPNG file containing TCP, TLS, and HTTP traffic to measure how long each communication phase takes for every connection and to calculate aggregated statistics.
- It reads the
SSLKEYLOGFILEenvironment variable.- It must point to a valid TLS key log file.
- This is used so Wireshark/TShark/PyShark can decrypt TLS traffic.
- It opens the PCAP with
pysharkusing the display filterhttp or tls or tcp. - It splits the original capture into multiple temporary PCAP files grouped by
tcp.stream.- This split is performed with
tshark. - The goal is to process the analysis in parallel and reduce total execution time.
- This split is performed with
- It processes each subset of streams in parallel with
multiprocessing. - For each TCP stream, it detects these timing phases:
TCP: from theSYNpacket toSYN-ACK.TCP delay: fromSYN-ACKto the TLSClientHello.TLS: fromClientHelloto TLSFinished.TLS delay: fromFinishedto the HTTPGETrequest.APP: from the HTTPGETrequest to the HTTP200 OKresponse.Total: the sum of all phases above.
- It converts all timings to milliseconds and prints aggregated statistics.
- It removes the temporary files generated during preprocessing.
The script does not use named CLI options. It only requires these inputs:
- Required environment variable:
SSLKEYLOGFILE- Path to the TLS key log file.
- If it does not exist or does not point to a valid file, the script exits with an error.
- Required positional argument:
<file.pcap>- Path to the PCAP/PCAPNG file to analyze.
Example usage:
SSLKEYLOGFILE=/ruta/al/sslkeys.log python3 pcap_layer_analysis.py captura.pcap
The output is written to the console through logging.
During execution, the script prints information such as:
- Number of streams used per temporary file.
- Temporary working directory.
- Number of files generated after splitting.
- Number of parallel workers used.
- Total number of TCP connections analyzed.
At the end, it prints a block of statistics in milliseconds for these categories:
TCPTCP_delayTLSTLS_delayAPPTOT
For each category, the output includes:
totalsamples, except forTOTmeanmedian, except forTOTp90p95p99maxminstd
For TOT, the script prints only:
meanstd
- Required input:
SSLKEYLOGFILE+ PCAP path. - Processes TCP streams in parallel.
- Measures TCP handshake, TLS handshake, transition to application traffic, and HTTP response timings.
- Returns aggregated statistics in the console; it does not generate an output file.
This project is distributed under the GNU General Public License v3.0.
See LICENSE for the full license text.