mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 11:17:08 +00:00
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.
This commit is contained in:
37
sbin/packet-capture.sh
Executable file
37
sbin/packet-capture.sh
Executable file
@@ -0,0 +1,37 @@
|
|||||||
|
#!/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"
|
||||||
Reference in New Issue
Block a user