#!/bin/bash # scan - a simple wifi scanner # Copyright 2011 Dave Woodfall # All rights reserved. # # Redistribution and use of this script, with or without modification, is # permitted provided that the following conditions are met: # # 1. Redistributions of this script must retain the above copyright # notice, this list of conditions and the following disclaimer. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # It takes only one argument and that is the interface. If that isn't done # it defaults to wlan0 # # keys 1 - 0 will print full info on a cell: # 1 - cell 01 # 2 - cell 02 etc # # q = quit # # It will work as user but for best results run as root. See man iwlist for # why. function init { trap "cleanup" EXIT HUP INT ABRT QUIT SEGV TERM KILL GREP_OPTIONS="" clear cyan='' bcyan='' bred='' bgreen='' byellow='' bblue='' bwhite="" white="" normal='\017' blank=".............................................................." blank=${blank//./\\040} c1=$cyan c2=$bwhite IFACE=$1 [[ -z $IFACE ]] && IFACE=wlan0 } function cleanup { echo " " exit 0 } function display_cell { cell=$1 scan=$(/sbin/iwlist $IFACE scan) let start=$(echo "$scan" | grep -n "Cell $cell" | cut -d: -f1)-1 let end=$(echo "$scan" | grep -n "Cell 0$((cell+1))" | cut -d: -f1)-1 if [ $start -eq -1 ]; then return fi if [ $end -eq -1 ]; then let end=$(echo "$scan" | wc -l) fi clear echo -en $bwhite echo "$scan" | head -n $end | tail -n $((end-start)) read -sn1 clear } function main { while true do tput cup 0 0 scan=$(/sbin/iwlist $IFACE scan | sed " /wlan0/d /Cipher/d /Extra/d /uthentication/d /^[ ]\{10\}/ s/^[ ]\{10\}//g /Cell.*$/ s/Cell.*$/ ${bwhite}&/g /Cell.*$/N; s/\n */ /g /Address:\ / s/Address:\ /Address:/g /Address:\ / s/Address:/$c1&$c2/g /ESSID:/ s/ESSID:/$c1&$c2/g /ESSID:/ s/ESSID.*$/& /g /Protocol.*$/d /Mode.*$/N;s/\n */ /g /Mode.*$/ s/Mode.*$/ & /g /Mode:/ s/Mode:/$c1&$c2/g /Frequency:/ s/Frequency:/${c1}Frequency:$c2/g /Encryption key:on/ s/Encryption key:on/ ${c1}Encryption key:${c2}on/g /Encryption key:off/ s/Encryption key:off/ ${c1}Encryption key:${bred}off/g /Quality=/ s/Quality=/${c1}Quality=$c2/g /Quality=/ s/Quality=.*$/ & /g / Signal level=/ s/ Signal level=/${c1}Signal level=$c2/g /IE:.*$/ s/IE:.*$/ & /g /IE: .*$/ s/IE: /${c1}IE:$c2/g /Mb\/s/d" | sed -n " /Encryption key.*$/ !{ p } /Encryption key.*$/ { h n G p } ") echo -e "$scan\n" let rows=$(stty size | cut -f1 -d' ') let lines=$(echo "$scan" | wc -l) if [ $lines -lt $rows ]; then for (( a=$((lines+3)); a<=$rows; a++)) do echo -e "$blank" done fi tput cup 0 0 read -sn1 -t1 option case $option in 'r') clear ;; '1') display_cell "01" ;; '2') display_cell "02" ;; '3') display_cell "03" ;; '4') display_cell "04" ;; '5') display_cell "05" ;; '6') display_cell "06" ;; '7') display_cell "07" ;; '8') display_cell "08" ;; '9') display_cell "09" ;; '0') display_cell "10" ;; 'q') cleanup ;; *) ;; esac done } init $1 main