[wifi] capture: gather system information

This commit is contained in:
Matteo Cypriani 2011-08-05 14:41:14 +02:00
parent f23d52b435
commit 65dd809c6b
2 changed files with 60 additions and 14 deletions

View File

@ -1,4 +1,5 @@
capture.sh is a script to automatically capture a few packets on a Wi-Fi
interface and write them to a compressed Pcap file. This file can then
be analysed (for example with Wireshark) to check what the interface
supports.
interface and write them to a Pcap file along with some information
about the system, which are finally compressed into a tarball. The Pcap
file can then be analysed (for example with Wireshark) to check what the
interface supports on which operating system, using a given driver, etc.

View File

@ -26,7 +26,8 @@
########################################################################
#
# Captures a few packets on a Wi-Fi interface, using Tcpdump, and
# writes them to a Pcap file.
# writes them to a Pcap file along with some information about the
# system. A tarball containing all these files is finally created.
#set -x
set -e
@ -43,24 +44,37 @@ error()
which tcpdump >/dev/null \
|| error "tcpdump is required to run this program!"
IFACE=$1
FILE=/tmp/capture.pcap
## Parameters (tune them if you want) ##
# Number of packet to capture:
NB_PKT=10
# Temporary directory:
TMP=/tmp
# Name of the capture file:
FILE=capture.pcap
## Generated parameters ##
# Interface to capture from:
IFACE=$1
# Machine information:
OS=`uname`
HOSTNAME=`uname -n`
echo -n "Shuting down interface $IFACE... "
ifconfig $IFACE down && echo "OK." \
|| error "Cannot shut down the interface!"
echo -n "Switching interface $IFACE to monitor mode... "
case `uname` in
case $OS in
Linux)
[ -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 \
&& echo "OK." \
|| error "Cannot switch the interface to mode monitor!" ;;
|| error "Cannot switch the interface to mode monitor!"
;;
*)
error "Your OS is not supported." ;;
error "Your OS is not supported."
;;
esac
echo -n "Turning up interface $IFACE... "
@ -68,11 +82,42 @@ ifconfig $IFACE up && echo "OK." \
|| error "Cannot turn the interface up!"
echo "Capturing $NB_PKT packets..."
tcpdump -i $IFACE -c $NB_PKT -w $FILE
echo "Capture file $FILE created."
DIR=$(mktemp -d "$TMP"/capture_${HOSTNAME}_${IFACE}-XXXXXXXX)
FILE="$DIR/$FILE"
tcpdump -i $IFACE -c $NB_PKT -w "$FILE"
echo "Capture file \"$FILE\" created."
gzip -9 $FILE
echo "Capture file compressed to $FILE.gz"
echo -n "Gathering system information... "
# Kernel & other information:
uname -a >"$DIR"/uname-a
# Wi-Fi interface information:
ifconfig $IFACE >"$DIR"/ifconfig_$IFACE
# PCI devices:
which lspci >/dev/null \
&& lspci >"$DIR"/lspci \
|| echo "lspci not available! Please install pciutils. "
# Loaded kernel modules & USB devices:
case $OS in
Linux)
lsmod >"$DIR"/lsmod
which lsusb >/dev/null \
&& lsusb >"$DIR"/lsusb \
|| echo "lsusb not available! Please install usbutils. "
;;
DragonFly)
kldstat >"$DIR"/kldstat
which usbstats >/dev/null \
&& usbstats >"$DIR"/usbstats \
|| echo "usbstats not available! Please install usbutil. "
;;
esac
echo "OK."
FILE="${DIR}.tar.gz"
DIR=`basename "$DIR"`
tar -C "$TMP" -czf "$FILE" "$DIR"
echo "Archive \"$FILE\" created."
rm -fr "$TMP/$DIR"
echo
echo "You can now shut down the interface $IFACE if you want:"