Files
dougal-software/sbin/packet-capture.sh
D. Berge d5aac5e84d Add network packet capture script.
The idea is to capture incoming real-time data to be able to
replay it later on development systems, e.g., for new development
or troubleshooting.

Issue #230.
2022-05-14 11:57:09 +02:00

38 lines
971 B
Bash
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
#
# Capture network packets for later replay on dev machines
#
# This should be run as root via a service.
#
OUTDIR="$(realpath "$(dirname "$0")/..")/var/pcap"
OUTNAME="capture-$(hostname)-$(date -u +%s)-$$-pcap"
OUTPATH="$OUTDIR/$OUTNAME"
# Inputs:
#
# 4461/UDP: GPS NMEA
# 4462/UDP: AIS NMEA
# 30000/UDP: Navigation system headers
# Not all inputs will be present in all systems.
#
EXPR="udp and (port 4461 or port 4462 or port 30000)"
if [[ ! -d "$OUTDIR" ]]; then
mkdir "$OUTDIR"
fi
# The size of each capture file is 50 MB (-C 50)
# and it will use a ring of 1000 files (-W 1000).
# The capture packet size is unlimited (-s 0).
#
# 50 MB (47.7 MiB) is about one day's worth of data
# so in theory it shouldn't overwrite files even if
# it was running continuously for over two years.
# NOTE: The above figures do not include AIS data.
echo "Logging to: $OUTPATH"
echo "Expression: $EXPR"
tcpdump -n -s 0 -W 1000 -C 50 -w "$OUTPATH" "$EXPR"