[wifi] capture: gather system information
This commit is contained in:
parent
f23d52b435
commit
65dd809c6b
|
@ -1,4 +1,5 @@
|
||||||
capture.sh is a script to automatically capture a few packets on a Wi-Fi
|
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
|
interface and write them to a Pcap file along with some information
|
||||||
be analysed (for example with Wireshark) to check what the interface
|
about the system, which are finally compressed into a tarball. The Pcap
|
||||||
supports.
|
file can then be analysed (for example with Wireshark) to check what the
|
||||||
|
interface supports on which operating system, using a given driver, etc.
|
||||||
|
|
|
@ -26,7 +26,8 @@
|
||||||
########################################################################
|
########################################################################
|
||||||
#
|
#
|
||||||
# Captures a few packets on a Wi-Fi interface, using Tcpdump, and
|
# 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 -x
|
||||||
set -e
|
set -e
|
||||||
|
@ -43,24 +44,37 @@ error()
|
||||||
which tcpdump >/dev/null \
|
which tcpdump >/dev/null \
|
||||||
|| error "tcpdump is required to run this program!"
|
|| error "tcpdump is required to run this program!"
|
||||||
|
|
||||||
IFACE=$1
|
## Parameters (tune them if you want) ##
|
||||||
FILE=/tmp/capture.pcap
|
# Number of packet to capture:
|
||||||
NB_PKT=10
|
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... "
|
echo -n "Shuting down interface $IFACE... "
|
||||||
ifconfig $IFACE down && echo "OK." \
|
ifconfig $IFACE down && echo "OK." \
|
||||||
|| error "Cannot shut down the interface!"
|
|| error "Cannot shut down the interface!"
|
||||||
|
|
||||||
echo -n "Switching interface $IFACE to monitor mode... "
|
echo -n "Switching interface $IFACE to monitor mode... "
|
||||||
case `uname` in
|
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 \
|
iwconfig $IFACE mode monitor \
|
||||||
&& echo "OK." \
|
&& 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
|
esac
|
||||||
|
|
||||||
echo -n "Turning up interface $IFACE... "
|
echo -n "Turning up interface $IFACE... "
|
||||||
|
@ -68,11 +82,42 @@ ifconfig $IFACE up && echo "OK." \
|
||||||
|| error "Cannot turn the interface up!"
|
|| error "Cannot turn the interface up!"
|
||||||
|
|
||||||
echo "Capturing $NB_PKT packets..."
|
echo "Capturing $NB_PKT packets..."
|
||||||
tcpdump -i $IFACE -c $NB_PKT -w $FILE
|
DIR=$(mktemp -d "$TMP"/capture_${HOSTNAME}_${IFACE}-XXXXXXXX)
|
||||||
echo "Capture file $FILE created."
|
FILE="$DIR/$FILE"
|
||||||
|
tcpdump -i $IFACE -c $NB_PKT -w "$FILE"
|
||||||
|
echo "Capture file \"$FILE\" created."
|
||||||
|
|
||||||
gzip -9 $FILE
|
echo -n "Gathering system information... "
|
||||||
echo "Capture file compressed to $FILE.gz"
|
# 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
|
||||||
echo "You can now shut down the interface $IFACE if you want:"
|
echo "You can now shut down the interface $IFACE if you want:"
|
||||||
|
|
Loading…
Reference in New Issue