| 1 | 2 | simandl | #!/bin/bash |
| 2 | 3 | simandl | # authors : Petr Simandl www.simandl.cz |
| 3 | 11 | simandl | # : Fyzik, Covex |
| 4 | | | # release date : 1/8/2003 |
| 5 | 2 | simandl | # name : wifimon |
| 6 | | | # description : hostap powered wifi card monitoring |
| 7 | | | # license : GPL |
| 8 | | | |
| 9 | 11 | simandl | wl_version="0.4beta6" |
| 10 | | | |
| 11 | | | wl_iwccmd="/usr/local/sbin/iwconfig" |
| 12 | 7 | simandl | wl_ifccmd="/sbin/ifconfig" |
| 13 | | | wl_hnmcmd="/bin/hostname" |
| 14 | 2 | simandl | wl_hostap="/proc/net/hostap/" |
| 15 | | | wl_wireless="/proc/net/wireless" |
| 16 | 3 | simandl | wl_arp="/proc/net/arp" |
| 17 | 11 | simandl | wl_dhcpcnf="/etc/dhcpd.conf" |
| 18 | 2 | simandl | |
| 19 | 4 | simandl | |
| 20 | 7 | simandl | wl_webpage="/tmp/wifimon.htm" |
| 21 | | | wl_header="<html><head><meta HTTP-EQUIV=\"Refresh\" CONTENT=\"3\"><title>Wifimon @ `$wl_hnmcmd`</title></head><body BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\"><pre>" |
| 22 | | | wl_footer="</pre></body></html>" |
| 23 | | | |
| 24 | | | wlm_no_managed_or_master=" neni ani Master ani Managed..." |
| 25 | | | wlm_number_of_clients="Pocet asociovanych klientu : " |
| 26 | | | wlm_unknown="Nezname parametry nebo neplatne jmeno rozhrani : " |
| 27 | | | #wlm_no_managed_or_master=" is not Master or Managed..." |
| 28 | | | #wlm_number_of_clients="Number of associated clients : " |
| 29 | | | |
| 30 | 11 | simandl | wlch_signal="=" |
| 31 | | | wlch_noise="*" |
| 32 | | | |
| 33 | 2 | simandl | ###################################################################### |
| 34 | 11 | simandl | w_col() |
| 35 | 10 | simandl | { |
| 36 | 11 | simandl | wlc_red=`tput setaf 1` |
| 37 | | | wlc_green=`tput setaf 2` |
| 38 | | | wlc_brown=`tput setaf 3` |
| 39 | | | wlc_blue=`tput setaf 4` |
| 40 | | | wlc_magenta=`tput setaf 5` |
| 41 | | | wlc_lblue=`tput setaf 6` |
| 42 | | | wlc_grey=`tput setaf 7` |
| 43 | | | wlc_std=`tput sgr0` |
| 44 | | | |
| 45 | | | wlc_ip=$wlc_lblue # ip address color |
| 46 | | | wlc_mac=$wlc_magenta # mac address color |
| 47 | | | wlc_sig=$wlc_red # signal number color |
| 48 | | | wlc_bar=$wlc_green # signal bar color |
| 49 | 10 | simandl | } |
| 50 | | | ###################################################################### |
| 51 | 4 | simandl | w_bw() |
| 52 | | | { |
| 53 | 6 | simandl | wlc_ip="" |
| 54 | | | wlc_mac="" |
| 55 | | | wlc_sig="" |
| 56 | | | wlc_bar="" |
| 57 | | | wlc_std="" |
| 58 | 4 | simandl | } |
| 59 | | | ###################################################################### |
| 60 | 2 | simandl | w_bar() |
| 61 | | | { |
| 62 | 4 | simandl | echo -n "${wlc_bar}" |
| 63 | 11 | simandl | wl_neg=`expr $wl_cnt \< 0 ` |
| 64 | | | if [ "$wl_neg" -eq 1 ] |
| 65 | | | then |
| 66 | | | wl_cnt=$(($wl_cnt * -1 )) |
| 67 | | | wl_bar=$wlch_noise |
| 68 | | | else |
| 69 | | | wl_bar=$wlch_signal |
| 70 | | | fi |
| 71 | 2 | simandl | until [ "$wl_cnt" -eq -1 ] |
| 72 | | | do |
| 73 | 11 | simandl | echo -n "$wl_bar" |
| 74 | 2 | simandl | wl_cnt=$(($wl_cnt - 1 )) |
| 75 | | | done |
| 76 | | | printf " \n" |
| 77 | 6 | simandl | echo -n "${wlc_std}" |
| 78 | 11 | simandl | # tput sgr0 |
| 79 | 2 | simandl | } # w_bar |
| 80 | | | |
| 81 | | | ###################################################################### |
| 82 | | | w_managed() |
| 83 | 7 | simandl | { echo $wl_iwctxt | awk '{print $1,$3,$4,$5" "}' |
| 84 | | | echo -n `$wl_ifccmd $wl_iface | grep -E "inet addr|inet adr" | awk '{print $2" "}' | sed s/ad*r://g`" " # IP adresa mastera z ifconfig |
| 85 | | | echo $wl_iwctxt | awk '{print $9,$6,$11" "}' |
| 86 | | | #echo $wl_iwctxt | awk '{print $27,$28,$29,$31,$32" "}' |
| 87 | | | #cat $wl_wireless | grep $wl_iface |
| 88 | | | wl_wtxt=`cat $wl_wireless | grep $wl_iface | awk '{print $3,$4,$5}' | sed 's/\.//g'` |
| 89 | | | wl_quality=`echo $wl_wtxt | awk '{print $1}'` |
| 90 | | | wl_signal=`echo $wl_wtxt | awk '{print $2}'` |
| 91 | 2 | simandl | wl_signal=$(($wl_signal - 256)) |
| 92 | 7 | simandl | wl_noise=`echo $wl_wtxt | awk '{print $3}'` |
| 93 | 2 | simandl | wl_noise=$(($wl_noise - 256)) |
| 94 | 5 | simandl | echo "Quality:${wlc_sig}$wl_quality${wlc_std}/92 Signal level:$wl_signal Noise level:$wl_noise " |
| 95 | 2 | simandl | wl_cnt=$wl_quality |
| 96 | | | w_bar |
| 97 | 7 | simandl | #wl_cnt=$(($wl_cnt + 100)) |
| 98 | | | #w_bar |
| 99 | 2 | simandl | echo |
| 100 | | | } # w_managed |
| 101 | | | |
| 102 | | | ###################################################################### |
| 103 | | | w_master() |
| 104 | 5 | simandl | { if [ $wcm_oneline -eq 0 ] |
| 105 | | | then |
| 106 | 7 | simandl | echo $wl_iwctxt | awk '{print $1,$3,$4,$5" "}' |
| 107 | | | echo $wl_iwctxt | awk '{print $6,$9,$11" "}' |
| 108 | 5 | simandl | else |
| 109 | 7 | simandl | echo $wl_iwctxt | awk '{print $1,$4,$5,$6,$11" "}' | sed 's/ [^": ]*:/ /g' |
| 110 | 5 | simandl | fi |
| 111 | 11 | simandl | |
| 112 | 2 | simandl | wl_numcl=`ls $wl_hostap$wl_iface | grep -c 00` |
| 113 | | | echo $wlm_number_of_clients $wl_numcl |
| 114 | 5 | simandl | wl_numcllast=$(($wl_numcllast + $wl_numcl)) |
| 115 | 3 | simandl | for wl_mac in `ls $wl_hostap$wl_iface | grep 00 ` |
| 116 | 2 | simandl | do |
| 117 | 11 | simandl | wl_macparam=`cat $wl_hostap$wl_iface/$wl_mac | grep -E 'last_rx|last_tx' | sed 's/last_//g'` |
| 118 | | | wl_signal=`echo $wl_macparam | awk '{print $5}' | sed 's/signal=//g'` |
| 119 | | | wl_silence=`echo $wl_macparam | awk '{print $4}' | sed 's/silence=//g'` |
| 120 | | | wl_cnt=$(($wl_signal - $wl_silence)) |
| 121 | 8 | simandl | wl_ipc=`cat $wl_arp | grep -i $wl_mac | awk '{print $1}'` # IP adresa peeru z arp tabulky |
| 122 | 11 | simandl | wl_name=`cat $wl_dhcpcnf | grep -i $wl_mac | awk '{print $2}'` |
| 123 | 5 | simandl | if [ $wcm_oneline -eq 0 ] |
| 124 | | | then |
| 125 | 11 | simandl | echo -n "$wl_name " |
| 126 | 5 | simandl | echo -n "${wlc_ip}$wl_ipc${wlc_std} " |
| 127 | 11 | simandl | echo -n "${wlc_mac}$wl_mac${wlc_std} Signal ${wlc_sig}$wl_cnt${wlc_std} " |
| 128 | | | echo $wl_macparam | awk '{print $1,$2" "}' |
| 129 | 5 | simandl | w_bar |
| 130 | | | else |
| 131 | 11 | simandl | echo -n "$wl_name " |
| 132 | | | #echo -n "${wlc_ip}$wl_ipc${wlc_std} " |
| 133 | | | echo -n "${wlc_mac}$wl_mac${wlc_std} ${wlc_sig}$wl_cnt${wlc_std} " |
| 134 | 7 | simandl | #echo -n $wl_macparam | awk '{print $1,$2" "}' |
| 135 | 5 | simandl | w_bar |
| 136 | | | fi |
| 137 | 4 | simandl | done |
| 138 | 11 | simandl | |
| 139 | | | echo |
| 140 | 2 | simandl | } # w_master |
| 141 | | | |
| 142 | | | ###################################################################### |
| 143 | | | w_iface() |
| 144 | 11 | simandl | { wl_iwctxt=`$wl_iwccmd $wl_iface 2>/dev/null | grep -v 'Device|Some|Extension' | sed 's/ Nick/_Nick/g'` |
| 145 | 7 | simandl | wl_mode=`echo $wl_iwctxt | awk '{print $5}' | sed 's/Mode://g'` |
| 146 | 2 | simandl | if [ "a$wl_mode" = "aManaged" ] |
| 147 | | | then |
| 148 | | | w_managed |
| 149 | 8 | simandl | elif [ "a$wl_mode" = "aAd-Hoc" ] |
| 150 | | | then |
| 151 | | | w_managed |
| 152 | 2 | simandl | elif [ "a$wl_mode" = "aMaster" ] |
| 153 | | | then |
| 154 | | | w_master |
| 155 | | | else |
| 156 | | | echo $wl_iface $wlm_no_managed_or_master |
| 157 | | | echo |
| 158 | | | fi |
| 159 | | | } |
| 160 | | | |
| 161 | | | ###################################################################### |
| 162 | 11 | simandl | w_version() |
| 163 | | | { |
| 164 | | | echo wifimon $wl_version |
| 165 | | | exit 0 |
| 166 | | | } |
| 167 | | | ###################################################################### |
| 168 | 5 | simandl | w_help() |
| 169 | | | { |
| 170 | 3 | simandl | echo Pouziti: wifimon [param] |
| 171 | | | echo param: |
| 172 | 11 | simandl | echo -v vypise verzi |
| 173 | 5 | simandl | echo -html generovani html stranky |
| 174 | 11 | simandl | echo -col barevny cyklicky vypis na obrazovku |
| 175 | 5 | simandl | echo -once vypsani jen jednoho vypisu a pak program skonci |
| 176 | | | echo -oneline vypsani klientu na jednu linku |
| 177 | | | echo -wlan0 -wlan1 -wlan2 vypise jen uvedene karty a to v danem poctu a poradi |
| 178 | 3 | simandl | echo bez parametru cyklicky vypis na obrazovku |
| 179 | 5 | simandl | exit 0 |
| 180 | | | } |
| 181 | | | ###################################################################### |
| 182 | | | ###################################################################### |
| 183 | 2 | simandl | |
| 184 | 5 | simandl | wl_unknown="" |
| 185 | | | wl_cnt=1 |
| 186 | | | wcm_clear=1 |
| 187 | | | wcm_once=0 |
| 188 | 11 | simandl | wcm_col=0 |
| 189 | 5 | simandl | wcm_oneline=0 |
| 190 | | | wcm_html=0 |
| 191 | | | wcm_ifc="" |
| 192 | | | |
| 193 | 6 | simandl | # parsing input parameters |
| 194 | 5 | simandl | while [ "a$1" != "a" ] |
| 195 | | | do |
| 196 | | | case $1 in |
| 197 | 11 | simandl | -v) |
| 198 | | | w_version |
| 199 | | | ;; |
| 200 | 5 | simandl | -help) |
| 201 | | | w_help |
| 202 | | | ;; |
| 203 | | | -once) |
| 204 | | | wcm_once=1 |
| 205 | | | shift |
| 206 | | | ;; |
| 207 | | | -oneline) |
| 208 | | | wcm_oneline=1 |
| 209 | | | shift |
| 210 | | | ;; |
| 211 | 11 | simandl | -col) |
| 212 | | | wcm_col=1 |
| 213 | 5 | simandl | shift |
| 214 | | | ;; |
| 215 | | | -html) |
| 216 | | | wcm_html=1 |
| 217 | | | shift |
| 218 | | | ;; |
| 219 | | | *) |
| 220 | | | wl_flg=0 |
| 221 | | | for wl_iface in `ls $wl_hostap` |
| 222 | | | do |
| 223 | | | if [ "a-$wl_iface" = "a$1" ] |
| 224 | | | then |
| 225 | | | wcm_ifc="$wcm_ifc $wl_iface" |
| 226 | | | wl_flg=1 |
| 227 | | | fi |
| 228 | | | done |
| 229 | | | if [ $wl_flg -eq 0 ] |
| 230 | | | then |
| 231 | | | wl_unknown="$wl_unknown$1 " |
| 232 | | | fi |
| 233 | | | shift |
| 234 | | | esac |
| 235 | | | done |
| 236 | | | |
| 237 | 6 | simandl | # printing the list of bad parameters (if there are some) |
| 238 | 5 | simandl | if [ "a$wl_unknown" != "a" ] |
| 239 | | | then |
| 240 | | | echo "$wlm_unknown $wl_unknown" |
| 241 | | | w_help |
| 242 | | | fi |
| 243 | | | |
| 244 | 6 | simandl | # if no interface is selected then all available are choosen |
| 245 | 5 | simandl | if [ "a$wcm_ifc" = "a" ] |
| 246 | | | then |
| 247 | | | wcm_ifc=`ls $wl_hostap` |
| 248 | | | fi |
| 249 | | | |
| 250 | 6 | simandl | # setting for old and last same value to avoid double clear after start |
| 251 | | | wl_numcllast=0 |
| 252 | | | wl_numclold=0 |
| 253 | | | for wl_iface in $wcm_ifc |
| 254 | | | do |
| 255 | | | wl_numcl=`ls $wl_hostap$wl_iface | grep -c 00` |
| 256 | | | wl_numcllast=$(($wl_numcllast + $wl_numcl)) |
| 257 | | | done |
| 258 | | | wl_numclold=$wl_numcllast |
| 259 | | | |
| 260 | 11 | simandl | if [ $wcm_col -eq 0 ] |
| 261 | 6 | simandl | then |
| 262 | | | w_bw |
| 263 | 11 | simandl | else |
| 264 | | | w_col |
| 265 | 6 | simandl | fi |
| 266 | | | |
| 267 | | | while [ 1 ] |
| 268 | 5 | simandl | do |
| 269 | | | if [ $wl_numcllast -ne $wl_numclold ] |
| 270 | | | then |
| 271 | | | wl_numclold=$wl_numcllast |
| 272 | | | wcm_clear=1 |
| 273 | | | fi |
| 274 | 11 | simandl | if [ $wcm_clear -eq 1 -a $wcm_html -ne 1 ] |
| 275 | 5 | simandl | then |
| 276 | 7 | simandl | clear |
| 277 | 5 | simandl | wcm_clear=0 |
| 278 | | | fi |
| 279 | | | wl_numcllast=0 |
| 280 | 7 | simandl | if [ $wcm_html -eq 1 ] |
| 281 | 5 | simandl | then |
| 282 | 11 | simandl | w_bw |
| 283 | 7 | simandl | echo $wl_header |
| 284 | | | for wl_iface in $wcm_ifc |
| 285 | | | do |
| 286 | | | w_iface |
| 287 | | | done |
| 288 | | | echo $wl_footer |
| 289 | | | else |
| 290 | | | tput cup 0 0 |
| 291 | | | for wl_iface in $wcm_ifc |
| 292 | | | do |
| 293 | | | w_iface |
| 294 | | | done |
| 295 | 5 | simandl | fi |
| 296 | 11 | simandl | |
| 297 | 5 | simandl | if [ $wcm_once -eq 1 ] |
| 298 | | | then |
| 299 | | | exit 0 |
| 300 | | | fi |
| 301 | | | sleep 1 |
| 302 | 6 | simandl | done |
| 303 | 5 | simandl | |
| 304 | | | exit 0 |
| 305 | | | |