User Tools

Site Tools


networking_misc:anydump

anydump.sh

#!/usr/bin/env bash
set -eu

# When this exits, exit all background processes:
trap 'kill $(jobs -p) &> /dev/null && sleep 0.2 &&  echo ' EXIT
# Create one tcpdump output per interface and add an identifier to the beginning of each line:
if [[ $@ =~ -i[[:space:]]?[^[:space:]]+ ]]; then
    tcpdump -l $@ | sed 's/^/[Interface:'"${BASH_REMATCH[0]:2}"'] /' &
else
    for interface in $(ifconfig | awk '/^[a-z0-9]/ {print $1}'); do
       tcpdump -l -i ${interface%:} -nn $@ | sed 's/^/[Interface'"$interface"']    /' &
    done
fi
# wait .. until CTRL+C
wait
  • USAGE: dump.sh [-i interface] [tcpdump-parameters]
  • DESCRIPTION: tcpdump on any interface and add the prefix [Interace:xy] in front of the dump data.
  • OPTIONS: same as tcpdump
  • REQUIREMENTS: bash, tcpdump, sed, ifconfig, kill, awk, grep, posix regex matching
  • AUTHOR: Sebastian Haas (I slightly tweaked it)
networking_misc/anydump.txt · Last modified: 2018/09/25 15:00 (external edit)