jablonka.czprosek.czf

wifimon

Subversion Repositories:
[/] [trunk/] [wifimon] - Blame information for rev 6

 

Line No. Rev Author Line
12simandl#!/bin/bash
23simandl# authors : Petr Simandl www.simandl.cz
36simandl# : Fyzik, Covex, Tydyt
4# release date : 04/10/2003
52simandl# name : wifimon
6# description : hostap powered wifi card monitoring
7# license : GPL
8 
96simandlwl_version="0.4.9"
10 
11PATH=$PATH:$HOME/bin:/bin:/sbin:/usr/bin:/usr/sbin:usr/local/bin:/usr/local/sbin
12 
13wl_iwccmd=`which iwconfig`
14wl_ifccmd=`which ifconfig`
15wl_hnmcmd=`which hostname`
16wl_clrcmd=`which clear`
17wl_tptcmd=`which tput`
18wl_awkcmd=`which awk`
19 
20wl_clrcmde=""
21 
222simandlwl_hostap="/proc/net/hostap/"
23wl_wireless="/proc/net/wireless"
243simandlwl_arp="/proc/net/arp"
256simandlwl_dhcpcnf="/etc/dhcpd.conf"
26wl_dhcplss="/var/lib/dhcp/dhcpd.leases"
272simandl 
286simandl#testing all settings
29 
30if [ "$wl_iwccmd x" = " x" ]
31 then
32 echo "iwconfig not found"
33 exit 1
34fi
35 
36if [ "$wl_ifccmd x" = " x" ]
37 then
38 echo "ifconfig not found"
39 exit 1
40fi
41 
42if [ "$wl_hnmcmd x" = " x" ]
43 then
44 echo "hostname not found"
45 exit 1
46fi
47 
48if [ "$wl_clrcmd x" = " x" ]
49 then
50 echo "clear not found"
51 wl_clear=0
52 else
53 wl_clear=1
54fi
55 
56if [ "$wl_tptcmd x" = " x" ]
57 then
58 echo "tput not found"
59 wl_tput=0
60 else
61 wl_tput=1
62fi
63 
64if [ "$wl_awkcmd x" = " x" ]
65 then
66 echo "awk not found"
67 exit 1
68fi
69 
70if [ -d $wl_hostap ]
71 then
72 wl_nop=1
73 else
74 echo "hostap not found"
75 exit 1
76fi
77 
78if [ -e $wl_wireless ]
79 then
80 wl_nop=1
81 else
82 echo "$wl_wireless not found"
83 exit 1
84fi
85 
86if [ -e $wl_arp ]
87 then
88 wl_nop=1
89 else
90 echo "$wl_arp not found"
91 exit 1
92fi
93 
94if [ -e $wl_dhcpcnf ]
95 then
96 wl_nop=1
97 else
98 echo "$wl_dhcpcnf not found"
99 wl_dhcpcnf="/dev/null"
100fi
101 
102if [ -e $wl_dhcplss ]
103 then
104 wl_nop=1
105 else
106 echo "$wl_dhcplss not found"
107 wl_dhcplss="/dev/null"
108fi
109 
110wl_header_refresh="<html><head><meta HTTP-EQUIV=\"Refresh\" CONTENT=\"3\"><title>Wifimon @ `$wl_hnmcmd`</title></head><body BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\"><pre>"
111wl_header="<html><head><title>Wifimon @ `$wl_hnmcmd`</title></head><body BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\"><pre>"
112wl_footer="</pre></body></html>"
113 
114wlm_no_managed_or_master=" neni ani Master ani Managed..."
115wlm_number_of_clients="Pocet asociovanych klientu : "
116wlm_unknown="Nezname parametry nebo neplatne jmeno rozhrani : "
117#wlm_no_managed_or_master=" is not Master or Managed..."
118#wlm_number_of_clients="Number of associated clients : "
119 
120wlch_signal="="
121wlch_noise="*"
122 
123######################################################################
124w_col()
125{
1264simandlwlc_red=`tput setaf 1`
127wlc_green=`tput setaf 2`
128wlc_brown=`tput setaf 3`
129wlc_blue=`tput setaf 4`
130wlc_magenta=`tput setaf 5`
131wlc_lblue=`tput setaf 6`
132wlc_grey=`tput setaf 7`
133wlc_std=`tput sgr0`
134 
135wlc_ip=$wlc_lblue # ip address color
136wlc_mac=$wlc_magenta # mac address color
137wlc_sig=$wlc_red # signal number color
138wlc_bar=$wlc_green # signal bar color
1396simandl}
1402simandl######################################################################
1414simandlw_bw()
142{
1436simandl wlc_ip=""
144 wlc_mac=""
145 wlc_sig=""
146 wlc_bar=""
147 wlc_std=""
1484simandl}
149######################################################################
1502simandlw_bar()
151{
1524simandl echo -n "${wlc_bar}"
1536simandl wl_neg=`expr $wl_cnt \< 0 `
154 if [ "$wl_neg" -eq 1 ]
155 then
156 wl_cnt=$(($wl_cnt * -1 ))
157 wl_bar=$wlch_noise
158 else
159 wl_bar=$wlch_signal
160 fi
1612simandl until [ "$wl_cnt" -eq -1 ]
162 do
1636simandl echo -n "$wl_bar"
1642simandl wl_cnt=$(($wl_cnt - 1 ))
165 done
166 printf " \n"
1676simandl echo -n "${wlc_std}"
168# tput sgr0
1692simandl} # w_bar
170 
171######################################################################
1726simandlw_pkts()
173{
174 wl_macpkts=`cat $wl_hostap$wl_iface/$wl_mac | grep -E 'rx\[|tx\[' | sed 's/=/ /g'`
175 wl_nt1=`echo $wl_macpkts | $wl_awkcmd '{print $2}'`
176 wl_nt2=`echo $wl_macpkts | $wl_awkcmd '{print $4}'`
177 wl_nt5=`echo $wl_macpkts | $wl_awkcmd '{print $6}'`
178 wl_nt11=`echo $wl_macpkts | $wl_awkcmd '{print $8}'`
179 wl_nr1=`echo $wl_macpkts | $wl_awkcmd '{print $10}'`
180 wl_nr2=`echo $wl_macpkts | $wl_awkcmd '{print $12}'`
181 wl_nr5=`echo $wl_macpkts | $wl_awkcmd '{print $14}'`
182 wl_nr11=`echo $wl_macpkts | $wl_awkcmd '{print $16}'`
183 
184 if [ $wcm_ppkts -eq 1 ]
185 then
186 wl_pksize=$((98))
187 wl_nt=$(($wl_nt1 + $wl_nt2 + wl_nt5 + wl_nt11))
188 if [ "$wl_nt1" -eq 0 ]
189 then
190 wl_nt1n="00"
191 else
192 wl_nt1n=$(($wl_pksize * $wl_nt1 / $wl_nt + 1))
193 [ "$wl_nt1n" -lt 10 ] && wl_nt1n="0"$wl_nt1n
194 fi
195 if [ "$wl_nt2" -eq 0 ]
196 then
197 wl_nt2n="00"
198 else
199 wl_nt2n=$(($wl_pksize * $wl_nt2 / $wl_nt + 1))
200 [ "$wl_nt2n" -lt 10 ] && wl_nt2n="0"$wl_nt2n
201 fi
202 if [ "$wl_nt5" -eq 0 ]
203 then
204 wl_nt5n="00"
205 else
206 wl_nt5n=$(($wl_pksize * $wl_nt5 / $wl_nt + 1))
207 [ "$wl_nt5n" -lt 10 ] && wl_nt5n="0"$wl_nt5n
208 fi
209 if [ "$wl_nt11" -eq 0 ]
210 then
211 wl_nt11n="00"
212 else
213 wl_nt11n=$(($wl_pksize * $wl_nt11 / $wl_nt + 1))
214 [ "$wl_nt11n" -lt 10 ] && wl_nt11n="0"$wl_nt11n
215 fi
216 wl_nr=$((1 + $wl_nr1 + $wl_nr2 + wl_nr5 + wl_nr11))
217 if [ "$wl_nr1" -eq 0 ]
218 then
219 wl_nr1n="00"
220 else
221 wl_nr1n=$(($wl_pksize * $wl_nr1 / $wl_nr + 1))
222 [ "$wl_nr1n" -lt 10 ] && wl_nr1n="0"$wl_nr1n
223 fi
224 if [ "$wl_nr2" -eq 0 ]
225 then
226 wl_nr2n="00"
227 else
228 wl_nr2n=$(($wl_pksize * $wl_nr2 / $wl_nr + 1))
229 [ "$wl_nr2n" -lt 10 ] && wl_nr2n="0"$wl_nr2n
230 fi
231 if [ "$wl_nr5" -eq 0 ]
232 then
233 wl_nr5n="00"
234 else
235 wl_nr5n=$(($wl_pksize * $wl_nr5 / $wl_nr + 1))
236 [ "$wl_nr5n" -lt 10 ] && wl_nr5n="0"$wl_nr5n
237 fi
238 if [ "$wl_nr11" -eq 0 ]
239 then
240 wl_nr11n="00"
241 else
242 wl_nr11n=$(($wl_pksize * $wl_nr11 / $wl_nr + 1))
243 [ "$wl_nr11n" -lt 10 ] && wl_nr11n="0"$wl_nr11n
244 fi
245 echo -n "Tx" $wl_nt1n $wl_nt2n $wl_nt5n $wl_nt11n "Rx" $wl_nr1n $wl_nr2n $wl_nr5n $wl_nr11n ""
246 fi
247 
248 [ $wcm_pkts -eq 1 ] && echo -n "Tx" $wl_nt1 $wl_nt2 $wl_nt5 $wl_nt11 "Rx" $wl_nr1 $wl_nr2 $wl_nr5 $wl_nr11 ""
249 
250} # w_pkts
251######################################################################
2522simandlw_managed()
2536simandl{ echo $wl_iwctxt | $wl_awkcmd '{print $1,$3,$4,$5" "}'
254 echo -n `$wl_ifccmd $wl_iface | grep -E "inet addr|inet adr" | $wl_awkcmd '{print $2" "}' | sed s/ad*r://g`" " # IP adresa mastera z ifconfig
255 echo $wl_iwctxt | $wl_awkcmd '{print $9,$6,$11" "}'
256 wl_wtxt=`cat $wl_wireless | grep $wl_iface | $wl_awkcmd '{print $3,$4,$5}' | sed 's/\.//g'`
257 wl_quality=`echo $wl_wtxt | $wl_awkcmd '{print $1}'`
258 wl_signal=`echo $wl_wtxt | $wl_awkcmd '{print $2}'`
2592simandl wl_signal=$(($wl_signal - 256))
2606simandl wl_noise=`echo $wl_wtxt | $wl_awkcmd '{print $3}'`
2612simandl wl_noise=$(($wl_noise - 256))
2625simandl echo "Quality:${wlc_sig}$wl_quality${wlc_std}/92 Signal level:$wl_signal Noise level:$wl_noise "
2632simandl wl_cnt=$wl_quality
264 w_bar
265 echo
266} # w_managed
267 
268######################################################################
269w_master()
2705simandl{ if [ $wcm_oneline -eq 0 ]
271 then
2726simandl echo $wl_iwctxt | $wl_awkcmd '{print $1,$3,$4,$5" "}'
273 echo $wl_iwctxt | $wl_awkcmd '{print $6,$9,$11" "}'
2745simandl else
2756simandl echo $wl_iwctxt | $wl_awkcmd '{print $1,$4,$5,$6,$11" "}' | sed 's/ [^": ]*:/ /g'
2765simandl fi
2772simandl 
278 wl_numcl=`ls $wl_hostap$wl_iface | grep -c 00`
279 echo $wlm_number_of_clients $wl_numcl
2806simandl 
2815simandl wl_numcllast=$(($wl_numcllast + $wl_numcl))
2826simandl 
2833simandl for wl_mac in `ls $wl_hostap$wl_iface | grep 00 `
2842simandl do
2856simandl wl_macparam=`cat $wl_hostap$wl_iface/$wl_mac | grep -E 'last_rx|last_tx' | sed 's/last_//g'`
286 wl_signal=`echo $wl_macparam | $wl_awkcmd '{print $5}' | sed 's/signal=//g'`
287 wl_silence=`echo $wl_macparam | $wl_awkcmd '{print $4}' | sed 's/silence=//g'`
288 wl_cnt=$(($wl_signal - $wl_silence))
289 wl_ipc=`cat $wl_arp | grep -i $wl_mac | $wl_awkcmd '{print $1}'` # IP adresa peeru z arp tabulky
290 
291 wl_name=`cat $wl_dhcpcnf | grep -i $wl_mac | $wl_awkcmd '{print $2}'`
292 if [ "$wl_name" = "ethernet" ] || [ "$wl_name" = "" ]
293 then
294 wl_name=`cat $wl_dhcpcnf | grep -i $wl_mac -B 1 | $wl_awkcmd '{print$2,$3}' | grep -i $wl_mac -v | $wl_awkcmd '{print$1}'`
295 if [ "$wl_name" = "" ]
296 then
297 wl_name=`cat $wl_dhcplss | grep -i $wl_mac -A 2 | $wl_awkcmd '{print$2,$3}' | grep -i $wl_mac -v | $wl_awkcmd '{print$1}'`
298 wl_name=`echo $wl_name | $wl_awkcmd '{print$1}' `
299 fi
300 fi
301 if [ $wcm_ppkts -eq 1 ] || [ $wcm_pkts -eq 1 ]
302 then
303 w_pkts
304 fi
305 
3065simandl if [ $wcm_oneline -eq 0 ]
307 then
3086simandl echo -n "$wl_name "
3095simandl echo -n "${wlc_ip}$wl_ipc${wlc_std} "
3106simandl echo -n "${wlc_mac}$wl_mac${wlc_std} Signal ${wlc_sig}$wl_cnt${wlc_std} "
311 echo $wl_macparam | $wl_awkcmd '{print $1,$2" "}'
3125simandl w_bar
313 else
3146simandl echo -n "$wl_name "
315 echo -n "${wlc_mac}$wl_mac${wlc_std} ${wlc_sig}$wl_cnt${wlc_std} "
3165simandl w_bar
317 fi
3184simandl done
3192simandl 
320 echo
321} # w_master
322 
323######################################################################
324w_iface()
3256simandl{ wl_iwctxt=`$wl_iwccmd $wl_iface 2>/dev/null | grep -v 'Device|Some|Extension' | sed 's/ Nick/_Nick/'`
326 wl_mode=`echo $wl_iwctxt | $wl_awkcmd '{print $5}' | sed 's/Mode://g'`
3272simandl if [ "a$wl_mode" = "aManaged" ]
328 then
329 w_managed
3306simandl elif [ "a$wl_mode" = "aAd-Hoc" ]
331 then
332 w_managed
3332simandl elif [ "a$wl_mode" = "aMaster" ]
334 then
335 w_master
336 else
337 echo $wl_iface $wlm_no_managed_or_master
338 echo
339 fi
340}
341 
342######################################################################
3436simandlw_version()
344{
345 echo wifimon $wl_version
346 exit 0
347}
348######################################################################
3495simandlw_help()
350{
3513simandl echo Pouziti: wifimon [param]
352 echo param:
3536simandl echo -v vypise verzi
3545simandl echo -html generovani html stranky
3556simandl echo -col barevny vypis na obrazovku
3565simandl echo -once vypsani jen jednoho vypisu a pak program skonci
357 echo -oneline vypsani klientu na jednu linku
3586simandl echo -ppkts vypsani procentniho pomeru 1M, 2M, 5.5M a 11M paketu pro jednotlive klienty
359 echo -pkts vypsani poctu 1M, 2M, 5.5M a 11M paketu pro jednotlive klienty
3605simandl echo -wlan0 -wlan1 -wlan2 vypise jen uvedene karty a to v danem poctu a poradi
3613simandl echo bez parametru cyklicky vypis na obrazovku
3625simandl exit 0
363}
364######################################################################
365######################################################################
3662simandl 
3675simandlwl_unknown=""
368wl_cnt=1
369wcm_clear=1
370wcm_once=0
371wcm_col=0
372wcm_oneline=0
373wcm_html=0
3746simandlwcm_ppkts=0
375wcm_pkts=0
3765simandlwcm_ifc=""
377 
3786simandl# parsing input parameters
3795simandlwhile [ "a$1" != "a" ]
380do
381 case $1 in
3826simandl -v)
383 w_version
384 ;;
3855simandl -help)
386 w_help
387 ;;
388 -once)
389 wcm_once=1
390 shift
391 ;;
392 -oneline)
393 wcm_oneline=1
394 shift
395 ;;
396 -col)
397 wcm_col=1
398 shift
399 ;;
400 -html)
401 wcm_html=1
402 shift
403 ;;
4046simandl -ppkts)
405 wcm_ppkts=1
406 shift
407 ;;
408 -pkts)
409 wcm_pkts=1
410 shift
411 ;;
4125simandl *)
413 wl_flg=0
414 for wl_iface in `ls $wl_hostap`
415 do
416 if [ "a-$wl_iface" = "a$1" ]
417 then
418 wcm_ifc="$wcm_ifc $wl_iface"
419 wl_flg=1
420 fi
421 done
422 if [ $wl_flg -eq 0 ]
423 then
424 wl_unknown="$wl_unknown$1 "
425 fi
426 shift
427 esac
428done
429 
4306simandl# printing the list of bad parameters (if there are some)
4315simandlif [ "a$wl_unknown" != "a" ]
432then
433 echo "$wlm_unknown $wl_unknown"
434 w_help
435fi
436 
4376simandl# if no interface is selected then all available are choosen
4385simandlif [ "a$wcm_ifc" = "a" ]
439then
440 wcm_ifc=`ls $wl_hostap`
441fi
442 
4436simandl# setting for old and last same value to avoid double clear after start
444wl_numcllast=0
445wl_numclold=0
446for wl_iface in $wcm_ifc
447do
448 wl_numcl=`ls $wl_hostap$wl_iface | grep -c 00`
449 wl_numcllast=$(($wl_numcllast + $wl_numcl))
450done
451wl_numclold=$wl_numcllast
452 
453if [ $wcm_col -eq 0 ]
454then
455 w_bw
456else
457 w_col
458fi
459 
460if [ $wcm_html -eq 1 ]
461then
462 w_bw
463 [ $wcm_once -eq 1 ] && echo $wl_header || echo $wl_header_refresh
464 for wl_iface in $wcm_ifc
465 do
466 w_iface
467 done
468 echo $wl_footer
469 exit 0
470fi
471 
472#this is main loop and it will be executer forever
473while [ 1 ]
4745simandl do
4756simandl 
476 # when the number of associated klients has changed we will set for clear screen
4775simandl if [ $wl_numcllast -ne $wl_numclold ]
478 then
479 wl_numclold=$wl_numcllast
480 wcm_clear=1
481 fi
4826simandl 
483 #if it is set for clear screen we will do it except we produce single report
484 if [ $wcm_clear -eq 1 -a $wcm_once -eq 0 ]
4855simandl then
4866simandl if [ $wl_clear -eq 1 ]
487 then
488 clear
489 else
490 echo -n $wl_clrcmde
491 fi
4925simandl wcm_clear=0
493 fi
494 wl_numcllast=0
4956simandl 
496 #for cyclic report we are trying to set cursor to the top left screen corner
497 if [ $wcm_once -eq 0 ]
4985simandl then
4996simandl #when tput is not found then we use clear. It is blinking but better than nothing
500 if [ $wl_tput -eq 1 ]
501 then
502 $wl_tptcmd cup 0 0
503 else
504 if [ $wl_clear -eq 1 ]
505 then
506 clear
507 else
508 echo -n $wl_clrcmde
509 fi
510 fi
5115simandl fi
512 
5136simandl #make report for all desired interfaces
514 for wl_iface in $wcm_ifc
515 do
516 w_iface
517 done
518 
519 #when a single report is needed than we are exiting
5205simandl if [ $wcm_once -eq 1 ]
521 then
522 exit 0
523 fi
524 sleep 1
5256simandldone
5265simandl 
527exit 0
528 

Powered by WebSVN 2.2.1