diff --git a/scripts/GOnnectlog2pcap.md b/scripts/GOnnectlog2pcap.md new file mode 100644 index 00000000..da1e904e --- /dev/null +++ b/scripts/GOnnectlog2pcap.md @@ -0,0 +1,50 @@ +# GOnnectlog2pcap.py + +Extract SIP messages from GOnnect/pjsua log files and write them to a PCAP file for analysis in Wireshark or tshark. + +## Features + +- Handles multiple log formats: + - File dump (ISO date + timezone) + - Console output (ANSI escape codes) + - journalctl dumps (locale-agnostic) + - Mixed timezone formats +- Supports IPv4 and IPv6 addresses +- Real timestamps extracted from log entries +- PCAP output with LINK_TYPE 228 (Wireshark auto-detects IPv4/IPv6) + +## Usage + +```bash +python3 GOnnectlog2pcap.py [output.pcap] +``` + +- `log_file` — path to the GOnnect/pjsua log file +- `output.pcap` — optional, defaults to `sip_messages.pcap` + +## Examples + +```bash +# Extract from a journalctl log +python3 GOnnectlog2pcap.py gonnect-journal.log + +# Extract with custom output filename +python3 GOnnectlog2pcap.py gonnect-journal.log capture.pcap + +# Inspect with tshark +tshark -r sip_messages.pcap -Y sip +``` + +## Supported Log Formats + +| Format | Example | +|--------|---------| +| File dump | `2026-05-21 13:37:16.128 CEST DEBUG ...` | +| Console | `[32m10:04:38.593[32m gonnect.pjsip: ...` | +| journalctl | `Mai 26 16:00:26 host app[pid]: 16:00:26.071 ...` | +| ISO + TZ | `2026-03-19 13:51:15.883 Mitteleuropäische Zeit ...` | + +## Requirements + +- Python 3.10+ +- No external dependencies (stdlib only) diff --git a/scripts/GOnnectlog2pcap.py b/scripts/GOnnectlog2pcap.py new file mode 100644 index 00000000..44bf05f2 --- /dev/null +++ b/scripts/GOnnectlog2pcap.py @@ -0,0 +1,266 @@ +#!/usr/bin/env python3 +"""Extract SIP messages from GOnnect/pjsua logs into a PCAP file for Wireshark. + +Handles multiple log formats: + - File dump: 2026-05-21 13:37:16.128 CEST DEBUG ... + - Console: [32m10:04:38.593[32m gonnect.pjsip: ... + - Journalctl: Mai 26 16:00:26 host app[pid]: 16:00:26.071 gonnect.pjsip: ... + - ISO date + local TZ: 2026-03-19 13:51:15.883 Mitteleuropäische Zeit ... + +Supports IPv4 and IPv6 addresses. +""" + +import datetime +import ipaddress +import re +import struct +import sys + +# ANSI escape codes +ANSI_RE = re.compile(r"\x1b\[[0-9;]*[a-zA-Z]") + +# journalctl prefix: