From f23d52b4353a9875d582aa821c0313aeeea79a60 Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Fri, 5 Aug 2011 10:30:10 +0200 Subject: [PATCH] [wifi] Add capture.sh capture.sh is a script to automatically capture a few packets on a Wi-Fi interface and write them to a Pcap file. --- wifi/README | 4 +++ wifi/capture.sh | 79 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 wifi/README create mode 100755 wifi/capture.sh diff --git a/wifi/README b/wifi/README new file mode 100644 index 0000000..7242fff --- /dev/null +++ b/wifi/README @@ -0,0 +1,4 @@ +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. diff --git a/wifi/capture.sh b/wifi/capture.sh new file mode 100755 index 0000000..665851e --- /dev/null +++ b/wifi/capture.sh @@ -0,0 +1,79 @@ +#!/bin/sh +# +# capture.sh, Copyright © 2011 Matteo Cypriani +# +######################################################################## +# This program is licensed under the terms of the Expat license. +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +######################################################################## +# +# Captures a few packets on a Wi-Fi interface, using Tcpdump, and +# writes them to a Pcap file. + +#set -x +set -e + +error() +{ + echo "$1" + exit 1 +} + +[ $# -eq 1 ] \ + || error "Usage: $0 " + +which tcpdump >/dev/null \ + || error "tcpdump is required to run this program!" + +IFACE=$1 +FILE=/tmp/capture.pcap +NB_PKT=10 + +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 + Linux) + [ -x /sbin/iwconfig ] \ + || 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 "Your OS is not supported." ;; +esac + +echo -n "Turning up interface $IFACE... " +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." + +gzip -9 $FILE +echo "Capture file compressed to $FILE.gz" + +echo +echo "You can now shut down the interface $IFACE if you want:" +echo " ifconfig $IFACE down"