[wifi] capture: test each channel
Try to capture on each channel, in case there is no traffic on the first channel.
This commit is contained in:
parent
ddfa6e0b49
commit
6739ade2a6
|
@ -32,12 +32,48 @@
|
|||
#set -x
|
||||
set -e
|
||||
|
||||
# Displays the message in argument and exits
|
||||
error()
|
||||
{
|
||||
echo "$1"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Switches the capture interface on the channel in argument
|
||||
set_channel()
|
||||
{
|
||||
echo -n "Setting interface $IFACE on channel $1... "
|
||||
case $OS in
|
||||
Linux)
|
||||
[ -x /sbin/iwconfig ] \
|
||||
|| error "iwconfig is required to run this program on Linux!"
|
||||
iwconfig $IFACE channel $1
|
||||
;;
|
||||
NetBSD)
|
||||
ifconfig $IFACE chan $1
|
||||
;;
|
||||
*)
|
||||
error "Your OS is not supported."
|
||||
;;
|
||||
esac \
|
||||
&& echo "OK." \
|
||||
|| error "Cannot set the channel!"
|
||||
}
|
||||
|
||||
# Invokes tcpdump and returns the number of packets captured
|
||||
invoke_tcpdump()
|
||||
{
|
||||
return $(tcpdump -i $IFACE -c $NB_PKT -w "$FILE" 2>&1 \
|
||||
| sed -n 's/ packets captured$//p')
|
||||
}
|
||||
|
||||
# Waits for a number of seconds, then kills any tcpdump process
|
||||
wait_tcpdump()
|
||||
{
|
||||
sleep $1
|
||||
pkill tcpdump
|
||||
}
|
||||
|
||||
[ $# -eq 1 ] \
|
||||
|| error "Usage: $0 <wifi_interface>"
|
||||
|
||||
|
@ -47,11 +83,13 @@ which tcpdump >/dev/null \
|
|||
## Parameters (tune them if you want) ##
|
||||
# Number of packet to capture:
|
||||
NB_PKT=10
|
||||
# Maximal time of a capture on a given channel:
|
||||
TIMEOUT=15
|
||||
# Temporary directory:
|
||||
TMP=/tmp
|
||||
# Name of the capture file:
|
||||
FILE=capture.pcap
|
||||
# Channel to scan
|
||||
# First channel to scan:
|
||||
CHANNEL=1
|
||||
|
||||
## Generated parameters ##
|
||||
|
@ -73,10 +111,10 @@ case $OS in
|
|||
Linux)
|
||||
[ -x /sbin/iwconfig ] \
|
||||
|| error "iwconfig is required to run this program on Linux!"
|
||||
iwconfig $IFACE mode monitor channel $CHANNEL
|
||||
iwconfig $IFACE mode monitor
|
||||
;;
|
||||
NetBSD)
|
||||
ifconfig $IFACE media autoselect mediaopt monitor chan $CHANNEL
|
||||
ifconfig $IFACE media autoselect mediaopt monitor
|
||||
;;
|
||||
*)
|
||||
error "Your OS is not supported."
|
||||
|
@ -89,12 +127,24 @@ echo -n "Turning up interface $IFACE... "
|
|||
ifconfig $IFACE up && echo "OK." \
|
||||
|| error "Cannot turn the interface up!"
|
||||
|
||||
echo "Capturing $NB_PKT packets..."
|
||||
echo "Trying to capture $NB_PKT packets..."
|
||||
DIR=$(mktemp -d \
|
||||
"$TMP"/capture_${OS}-${OS_RELEASE}_${IFACE}_${HOSTNAME}_${DATE}_XX)
|
||||
FILE="$DIR/$FILE"
|
||||
tcpdump -i $IFACE -c $NB_PKT -w "$FILE"
|
||||
echo "Capture file \"$FILE\" created."
|
||||
CAPTURED=0
|
||||
while [ $CAPTURED -eq 0 -a $CHANNEL -le 14 ] ; do
|
||||
set_channel $CHANNEL
|
||||
wait_tcpdump $TIMEOUT &
|
||||
invoke_tcpdump
|
||||
CAPTURED=$?
|
||||
[ $CAPTURED -eq 0 ] \
|
||||
&& echo "No packet captured on channel $CHANNEL."
|
||||
CHANNEL=`expr $CHANNEL + 1`
|
||||
done
|
||||
|
||||
[ $CAPTURED -gt 0 ] \
|
||||
&& echo "Capture file \"$FILE\" created with $CAPTURED packets." \
|
||||
|| error "Failed to capture any packet!"
|
||||
|
||||
echo -n "Gathering system information... "
|
||||
# Kernel & other information:
|
||||
|
|
Loading…
Reference in New Issue