#!/bin/sh
# Get a list of interface names from a user by an argument. (e.g. 'eth0 wlan0')
# Note that the list of interfaces separated by a space should be inside '' or "".
IFLIST=$1
# 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 the interface name in front of each line:
for interface in $IFLIST
do
tcpdump -l -i $interface -Nn -b ip -tttt | sed 's/^/'"$interface"' /' 2>/dev/null &
done
# Wait until Ctrl+C
wait
무선 인터페이스 3개(wlan0, wlan1, wlan2)를 모니터링할 경우,
$ sudo ./anydump2.sh 'wlan0 wlan1 wlan2'
cdsn@cdsn-HP-EliteBook-2740p:~/exp/tcpdm-monitor$ sudo ./anydump2.sh 'wlan0 wlan1 wlan2'
[sudo] password for cdsn:
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on wlan0, link-type EN10MB (Ethernet), capture size 65535 bytes
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on wlan2, link-type EN10MB (Ethernet), capture size 65535 bytes
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on wlan1, link-type EN10MB (Ethernet), capture size 65535 bytes
wlan0 2016-09-05 17:42:41.671768 IP 192.168.4.6 > 192.168.4.5: ICMP echo request, id 2210, seq 1, length 64
wlan0 2016-09-05 17:42:41.671861 IP 192.168.4.5 > 192.168.4.6: ICMP echo reply, id 2210, seq 1, length 64
wlan0 2016-09-05 17:42:42.650726 IP 192.168.4.6 > 192.168.4.5: ICMP echo request, id 2210, seq 2, length 64
wlan0 2016-09-05 17:42:42.650783 IP 192.168.4.5 > 192.168.4.6: ICMP echo reply, id 2210, seq 2, length 64
wlan0 2016-09-05 17:42:43.650913 IP 192.168.4.6 > 192.168.4.5: ICMP echo request, id 2210, seq 3, length 64
wlan0 2016-09-05 17:42:43.650952 IP 192.168.4.5 > 192.168.4.6: ICMP echo reply, id 2210, seq 3, length 64
wlan1 2016-09-05 17:42:47.740037 IP 192.168.3.6 > 192.168.3.5: ICMP echo request, id 2211, seq 2, length 64
wlan1 2016-09-05 17:42:47.740121 IP 192.168.3.5 > 192.168.3.6: ICMP echo reply, id 2211, seq 2, length 64
wlan1 2016-09-05 17:42:48.752034 IP 192.168.3.6 > 192.168.3.5: ICMP echo request, id 2211, seq 3, length 64
wlan1 2016-09-05 17:42:48.752080 IP 192.168.3.5 > 192.168.3.6: ICMP echo reply, id 2211, seq 3, length 64
wlan1 2016-09-05 17:42:49.747415 IP 192.168.3.6 > 192.168.3.5: ICMP echo request, id 2211, seq 4, length 64
wlan1 2016-09-05 17:42:49.747452 IP 192.168.3.5 > 192.168.3.6: ICMP echo reply, id 2211, seq 4, length 64
^C6 packets captured6 packets captured
6 packets received by filter6 packets received by filter
0 packets dropped by kernel0 packets dropped by kernel
0 packets captured
0 packets received by filter
0 packets dropped by kernel
wlan1
wlan0
wlan2
cdsn@cdsn-HP-EliteBook-2740p:~/exp/tcpdm-monitor$