[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 -x
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
# Displays the message in argument and exits
|
||||||
error()
|
error()
|
||||||
{
|
{
|
||||||
echo "$1"
|
echo "$1"
|
||||||
exit 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 ] \
|
[ $# -eq 1 ] \
|
||||||
|| error "Usage: $0 <wifi_interface>"
|
|| error "Usage: $0 <wifi_interface>"
|
||||||
|
|
||||||
|
@ -47,11 +83,13 @@ which tcpdump >/dev/null \
|
||||||
## Parameters (tune them if you want) ##
|
## Parameters (tune them if you want) ##
|
||||||
# Number of packet to capture:
|
# Number of packet to capture:
|
||||||
NB_PKT=10
|
NB_PKT=10
|
||||||
|
# Maximal time of a capture on a given channel:
|
||||||
|
TIMEOUT=15
|
||||||
# Temporary directory:
|
# Temporary directory:
|
||||||
TMP=/tmp
|
TMP=/tmp
|
||||||
# Name of the capture file:
|
# Name of the capture file:
|
||||||
FILE=capture.pcap
|
FILE=capture.pcap
|
||||||
# Channel to scan
|
# First channel to scan:
|
||||||
CHANNEL=1
|
CHANNEL=1
|
||||||
|
|
||||||
## Generated parameters ##
|
## Generated parameters ##
|
||||||
|
@ -73,10 +111,10 @@ case $OS in
|
||||||
Linux)
|
Linux)
|
||||||
[ -x /sbin/iwconfig ] \
|
[ -x /sbin/iwconfig ] \
|
||||||
|| error "iwconfig is required to run this program on Linux!"
|
|| error "iwconfig is required to run this program on Linux!"
|
||||||
iwconfig $IFACE mode monitor channel $CHANNEL
|
iwconfig $IFACE mode monitor
|
||||||
;;
|
;;
|
||||||
NetBSD)
|
NetBSD)
|
||||||
ifconfig $IFACE media autoselect mediaopt monitor chan $CHANNEL
|
ifconfig $IFACE media autoselect mediaopt monitor
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
error "Your OS is not supported."
|
error "Your OS is not supported."
|
||||||
|
@ -89,12 +127,24 @@ echo -n "Turning up interface $IFACE... "
|
||||||
ifconfig $IFACE up && echo "OK." \
|
ifconfig $IFACE up && echo "OK." \
|
||||||
|| error "Cannot turn the interface up!"
|
|| error "Cannot turn the interface up!"
|
||||||
|
|
||||||
echo "Capturing $NB_PKT packets..."
|
echo "Trying to capture $NB_PKT packets..."
|
||||||
DIR=$(mktemp -d \
|
DIR=$(mktemp -d \
|
||||||
"$TMP"/capture_${OS}-${OS_RELEASE}_${IFACE}_${HOSTNAME}_${DATE}_XX)
|
"$TMP"/capture_${OS}-${OS_RELEASE}_${IFACE}_${HOSTNAME}_${DATE}_XX)
|
||||||
FILE="$DIR/$FILE"
|
FILE="$DIR/$FILE"
|
||||||
tcpdump -i $IFACE -c $NB_PKT -w "$FILE"
|
CAPTURED=0
|
||||||
echo "Capture file \"$FILE\" created."
|
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... "
|
echo -n "Gathering system information... "
|
||||||
# Kernel & other information:
|
# Kernel & other information:
|
||||||
|
|
Loading…
Reference in New Issue