User Tools

Site Tools


networking_misc:anydump

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

networking_misc:anydump [2018/09/25 13:00] (current)
Line 1: Line 1:
 +====== anydump.sh ======
  
 +<​code>​
 +#​!/​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
 +</​code>​
 +
 +  * 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 13:00 (external edit)