jablonka.czprosek.czf

wifimon

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

 

Line No. Rev Author Line
12simandl#!/bin/bash
23simandl# authors : Petr Simandl www.simandl.cz
314simandl# : Fyzik, Covex, Tydyt
418simandl# release date : 13/06/2005
52simandl# name : wifimon
6# description : hostap powered wifi card monitoring
7# license : GPL
8 
918simandlwl_version="0.5.4"
1011simandl 
1113simandlPATH=$PATH:$HOME/bin:/bin:/sbin:/usr/bin:/usr/sbin:usr/local/bin:/usr/local/sbin
12 
1314simandlwl_iwccmd=`which iwconfig`
14wl_ifccmd=`which ifconfig`
15wl_hnmcmd=`which hostname`
16wl_awkcmd=`which awk`
17 
18wl_tptcmde=""
19wl_clrcmde=""
20 
21wl_hostap="/proc/net/hostap/"
22wl_wireless="/proc/net/wireless"
23wl_arp="/proc/net/arp"
24wl_dhcpcnf="/etc/dhcpd.conf"
25wl_dhcplss="/var/lib/dhcp/dhcpd.leases"
2617simandl# wl_dhcpcnf="/etc/dhcp3/dhcpd.conf"
27# wl_dhcplss="/var/lib/dhcp3/dhcpd.leases"
2814simandl 
29#testing all settings
30 
3112simandlif [ "$wl_iwccmd x" = " x" ]
32 then
33 echo "iwconfig not found"
34 exit 1
35fi
362simandl 
3714simandlif [ "$wl_ifccmd x" = " x" ]
38 then
39 echo "ifconfig not found"
40 exit 1
41fi
424simandl 
4314simandlif [ "$wl_hnmcmd x" = " x" ]
44 then
45 echo "hostname not found"
46 exit 1
47fi
48 
49if [ "$wl_awkcmd x" = " x" ]
50 then
51 echo "awk not found"
52 exit 1
53fi
54 
55if [ -d $wl_hostap ]
56 then
57 wl_nop=1
58 else
59 echo "hostap not found"
60 exit 1
61fi
62 
63if [ -e $wl_wireless ]
64 then
65 wl_nop=1
66 else
67 echo "$wl_wireless not found"
68 exit 1
69fi
70 
71if [ -e $wl_arp ]
72 then
73 wl_nop=1
74 else
75 echo "$wl_arp not found"
76 exit 1
77fi
78 
79if [ -e $wl_dhcpcnf ]
80 then
81 wl_nop=1
82 else
83 echo "$wl_dhcpcnf not found"
84 wl_dhcpcnf="/dev/null"
85fi
86 
87if [ -e $wl_dhcplss ]
88 then
89 wl_nop=1
90 else
91 echo "$wl_dhcplss not found"
92 wl_dhcplss="/dev/null"
93fi
94 
9515simandlwl_header_refresh="<html><head><meta HTTP-EQUIV=\"Refresh\" CONTENT=\"15\"><title>Wifimon @ `$wl_hnmcmd`</title></head><body BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\"><pre>"
9613simandlwl_header="<html><head><title>Wifimon @ `$wl_hnmcmd`</title></head><body BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\"><pre>"
977simandlwl_footer="</pre></body></html>"
98 
99wlm_no_managed_or_master=" neni ani Master ani Managed..."
100wlm_number_of_clients="Pocet asociovanych klientu : "
101wlm_unknown="Nezname parametry nebo neplatne jmeno rozhrani : "
102#wlm_no_managed_or_master=" is not Master or Managed..."
103#wlm_number_of_clients="Number of associated clients : "
104 
10511simandlwlch_signal="="
106wlch_noise="*"
107 
1082simandl######################################################################
10911simandlw_col()
11010simandl{
11115simandlwlc_red=`tput setaf 1` # ruda (Red)
112wlc_green=`tput setaf 2` # zelena (Lime)
113wlc_brown=`tput setaf 3` # zluta (Yellow)
114wlc_blue=`tput setaf 4` # modra (Blue)
115wlc_magenta=`tput setaf 5` # fialova (Fuchsia)
116wlc_lblue=`tput setaf 6` # svetle modra (Aqua)
117wlc_grey=`tput setaf 7` # bila (White)
11811simandlwlc_std=`tput sgr0`
119 
12015simandlwlc_pkts=$wlc_red # Rx,Tx info color
12111simandlwlc_ip=$wlc_lblue # ip address color
122wlc_mac=$wlc_magenta # mac address color
12315simandlwlc_name=$wlc_magenta # host name color
12411simandlwlc_sig=$wlc_red # signal number color
125wlc_bar=$wlc_green # signal bar color
12615simandlwlc_noise=$wlc_red # Signal noise color
12710simandl}
128######################################################################
12915simandlw_colh()
130{
131 wlh_pkts="Olive" # signal number color html
132 wlh_ip="Blue" # ip address color html
133 wlh_mac="Fuchsia" # mac address color html
134 wlh_name="Fuchsia" # Host name color html
135 wlh_sig="Red" # signal number color html
136 wlh_bar="Lime" # signal bar color html
137 wlh_noise="Red" # Signal noise color html
138 
139 wlc_pkts="<font color=\"$wlh_pkts\">"
140 wlc_ip="<font color=\"$wlh_ip\">"
141 wlc_mac="<font color=\"$wlh_mac\">"
142 wlc_name="<font color=\"$wlh_name\">"
143 wlc_sig="<font color=\"$wlh_sig\">"
144 wlc_bar="<font color=\"$wlh_bar\">"
145 wlc_noise="<font color=\"$wlh_noise\">"
146 wlc_std="</font>"
147}
148######################################################################
1494simandlw_bw()
150{
15115simandl wlc_pkts=""
1526simandl wlc_ip=""
153 wlc_mac=""
154 wlc_sig=""
155 wlc_bar=""
15615simandl wlc_noise=""
1576simandl wlc_std=""
1584simandl}
159######################################################################
1602simandlw_bar()
161{
16211simandl wl_neg=`expr $wl_cnt \< 0 `
163 if [ "$wl_neg" -eq 1 ]
164 then
16515simandl echo -n "${wlc_noise}"
16611simandl wl_cnt=$(($wl_cnt * -1 ))
167 wl_bar=$wlch_noise
168 else
16915simandl echo -n "${wlc_bar}"
17011simandl wl_bar=$wlch_signal
171 fi
1722simandl until [ "$wl_cnt" -eq -1 ]
173 do
17411simandl echo -n "$wl_bar"
1752simandl wl_cnt=$(($wl_cnt - 1 ))
176 done
177 printf " \n"
1786simandl echo -n "${wlc_std}"
17911simandl# tput sgr0
1802simandl} # w_bar
181 
182######################################################################
18313simandlw_pkts()
184{
185 wl_macpkts=`cat $wl_hostap$wl_iface/$wl_mac | grep -E 'rx\[|tx\[' | sed 's/=/ /g'`
18614simandl wl_nt1=`echo $wl_macpkts | $wl_awkcmd '{print $2}'`
187 wl_nt2=`echo $wl_macpkts | $wl_awkcmd '{print $4}'`
188 wl_nt5=`echo $wl_macpkts | $wl_awkcmd '{print $6}'`
189 wl_nt11=`echo $wl_macpkts | $wl_awkcmd '{print $8}'`
190 wl_nr1=`echo $wl_macpkts | $wl_awkcmd '{print $10}'`
191 wl_nr2=`echo $wl_macpkts | $wl_awkcmd '{print $12}'`
192 wl_nr5=`echo $wl_macpkts | $wl_awkcmd '{print $14}'`
193 wl_nr11=`echo $wl_macpkts | $wl_awkcmd '{print $16}'`
19413simandl 
195 if [ $wcm_ppkts -eq 1 ]
196 then
197 wl_pksize=$((98))
198 wl_nt=$(($wl_nt1 + $wl_nt2 + wl_nt5 + wl_nt11))
199 if [ "$wl_nt1" -eq 0 ]
200 then
201 wl_nt1n="00"
202 else
203 wl_nt1n=$(($wl_pksize * $wl_nt1 / $wl_nt + 1))
204 [ "$wl_nt1n" -lt 10 ] && wl_nt1n="0"$wl_nt1n
205 fi
206 if [ "$wl_nt2" -eq 0 ]
207 then
208 wl_nt2n="00"
209 else
210 wl_nt2n=$(($wl_pksize * $wl_nt2 / $wl_nt + 1))
211 [ "$wl_nt2n" -lt 10 ] && wl_nt2n="0"$wl_nt2n
212 fi
213 if [ "$wl_nt5" -eq 0 ]
214 then
215 wl_nt5n="00"
216 else
217 wl_nt5n=$(($wl_pksize * $wl_nt5 / $wl_nt + 1))
218 [ "$wl_nt5n" -lt 10 ] && wl_nt5n="0"$wl_nt5n
219 fi
220 if [ "$wl_nt11" -eq 0 ]
221 then
222 wl_nt11n="00"
223 else
224 wl_nt11n=$(($wl_pksize * $wl_nt11 / $wl_nt + 1))
225 [ "$wl_nt11n" -lt 10 ] && wl_nt11n="0"$wl_nt11n
226 fi
227 wl_nr=$((1 + $wl_nr1 + $wl_nr2 + wl_nr5 + wl_nr11))
228 if [ "$wl_nr1" -eq 0 ]
229 then
230 wl_nr1n="00"
231 else
232 wl_nr1n=$(($wl_pksize * $wl_nr1 / $wl_nr + 1))
233 [ "$wl_nr1n" -lt 10 ] && wl_nr1n="0"$wl_nr1n
234 fi
235 if [ "$wl_nr2" -eq 0 ]
236 then
237 wl_nr2n="00"
238 else
239 wl_nr2n=$(($wl_pksize * $wl_nr2 / $wl_nr + 1))
240 [ "$wl_nr2n" -lt 10 ] && wl_nr2n="0"$wl_nr2n
241 fi
242 if [ "$wl_nr5" -eq 0 ]
243 then
244 wl_nr5n="00"
245 else
246 wl_nr5n=$(($wl_pksize * $wl_nr5 / $wl_nr + 1))
247 [ "$wl_nr5n" -lt 10 ] && wl_nr5n="0"$wl_nr5n
248 fi
249 if [ "$wl_nr11" -eq 0 ]
250 then
251 wl_nr11n="00"
252 else
253 wl_nr11n=$(($wl_pksize * $wl_nr11 / $wl_nr + 1))
254 [ "$wl_nr11n" -lt 10 ] && wl_nr11n="0"$wl_nr11n
255 fi
25615simandl echo -n "Tx"${wlc_pkts} $wl_nt1n $wl_nt2n $wl_nt5n $wl_nt11n ${wlc_std}""
257 echo -n "Rx"${wlc_pkts} $wl_nr1n $wl_nr2n $wl_nr5n $wl_nr11n ${wlc_std}""
25813simandl fi
259 
260 [ $wcm_pkts -eq 1 ] && echo -n "Tx" $wl_nt1 $wl_nt2 $wl_nt5 $wl_nt11 "Rx" $wl_nr1 $wl_nr2 $wl_nr5 $wl_nr11 ""
261 
262} # w_pkts
263######################################################################
26417simandlw_managed()
265{ echo $wl_iwctxt | $wl_awkcmd '{print $1,$3,$4,$5" "}'
26618simandl 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
26715simandl 
26818simandl if [ $wcm_macoff -eq 0 ]
26915simandl then
27018simandl wl_mac=`echo -n $wl_iwctxt | $wl_awkcmd '{print $8}'`
271 echo -n "${wlc_mac}$wl_mac${wlc_std} "
27215simandl fi
27318simandl echo $wl_iwctxt | $wl_awkcmd '{print $6,$10" "}'
27415simandl 
27514simandl wl_wtxt=`cat $wl_wireless | grep $wl_iface | $wl_awkcmd '{print $3,$4,$5}' | sed 's/\.//g'`
276 wl_quality=`echo $wl_wtxt | $wl_awkcmd '{print $1}'`
277 wl_signal=`echo $wl_wtxt | $wl_awkcmd '{print $2}'`
2782simandl wl_signal=$(($wl_signal - 256))
27914simandl wl_noise=`echo $wl_wtxt | $wl_awkcmd '{print $3}'`
2802simandl wl_noise=$(($wl_noise - 256))
2815simandl echo "Quality:${wlc_sig}$wl_quality${wlc_std}/92 Signal level:$wl_signal Noise level:$wl_noise "
2822simandl wl_cnt=$wl_quality
283 w_bar
284 echo
285} # w_managed
286 
287######################################################################
288w_master()
28917simandl{ if [ $wcm_oneline -eq 0 ]
2905simandl then
29114simandl echo $wl_iwctxt | $wl_awkcmd '{print $1,$3,$4,$5" "}'
29215simandl if [ $wcm_macoff -eq 1 ]
293 then
29417simandl echo $wl_iwctxt | $wl_awkcmd '{print $6,$11" "}'
29515simandl else
29617simandl echo $wl_iwctxt | $wl_awkcmd '{print $6,$9,$11" "}'
29715simandl fi
2985simandl else
29917simandl echo $wl_iwctxt | $wl_awkcmd '{print $1,$4,$5,$6,$11" "}' | sed 's/ [^": ]*:/ /g'
3005simandl fi
3012simandl wl_numcl=`ls $wl_hostap$wl_iface | grep -c 00`
302 echo $wlm_number_of_clients $wl_numcl
30313simandl 
3045simandl wl_numcllast=$(($wl_numcllast + $wl_numcl))
30513simandl 
3063simandl for wl_mac in `ls $wl_hostap$wl_iface | grep 00 `
3072simandl do
30811simandl wl_macparam=`cat $wl_hostap$wl_iface/$wl_mac | grep -E 'last_rx|last_tx' | sed 's/last_//g'`
30916simandl wl_signal=`echo $wl_macparam | $wl_awkcmd '{print $6}' | sed 's/signal=//g'`
31014simandl wl_silence=`echo $wl_macparam | $wl_awkcmd '{print $4}' | sed 's/silence=//g'`
31111simandl wl_cnt=$(($wl_signal - $wl_silence))
31214simandl wl_ipc=`cat $wl_arp | grep -i $wl_mac | $wl_awkcmd '{print $1}'` # IP adresa peeru z arp tabulky
31313simandl 
31414simandl wl_name=`cat $wl_dhcpcnf | grep -i $wl_mac | $wl_awkcmd '{print $2}'`
315 if [ "$wl_name" = "ethernet" ] || [ "$wl_name" = "" ]
316 then
317 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}'`
318 if [ "$wl_name" = "" ]
319 then
32017simandl wl_name=`cat $wl_dhcplss | grep -i $wl_mac -A 2 | grep -i client-hostname | $wl_awkcmd '{print$2}'`
32114simandl wl_name=`echo $wl_name | $wl_awkcmd '{print$1}' `
322 fi
323 fi
32413simandl if [ $wcm_ppkts -eq 1 ] || [ $wcm_pkts -eq 1 ]
325 then
326 w_pkts
327 fi
328 
3295simandl if [ $wcm_oneline -eq 0 ]
330 then
33115simandl echo -n "${wlc_name}$wl_name${wlc_std} "
3325simandl echo -n "${wlc_ip}$wl_ipc${wlc_std} "
33315simandl if [ $wcm_macoff -eq 0 ]
334 then
335 echo -n "${wlc_mac}$wl_mac${wlc_std} "
336 fi
337 if [ $wcm_threeline -eq 1 ]
338 then
339 echo ""
340 echo -n " "
341 fi
342 echo -n "Signal ${wlc_sig}$wl_cnt${wlc_std} "
343 if [ $wcm_rxtx -eq 0 ]
344 then
345 echo ""
346 else
34717simandl echo $wl_macparam | $wl_awkcmd '{print $1,$2" "}'
34815simandl fi
3495simandl w_bar
350 else
35115simandl if [ $wcm_macoff -eq 0 ]
352 then
353 echo -n "${wlc_mac}$wl_mac${wlc_std} "
354 fi
355 echo -n "${wlc_sig}$wl_cnt${wlc_std} "
35617simandl echo -n "$wl_name "
3575simandl w_bar
358 fi
3594simandl done
36011simandl 
361 echo
3622simandl} # w_master
363 
364######################################################################
365w_iface()
36618simandl{ wl_iwctxt=`$wl_iwccmd $wl_iface 2>/dev/null | grep -v 'Device|Some|Extension' | sed 's/ Nick/_Nick/' | sed 's/Access Point/Access_Point/'`
36714simandl wl_mode=`echo $wl_iwctxt | $wl_awkcmd '{print $5}' | sed 's/Mode://g'`
3682simandl if [ "a$wl_mode" = "aManaged" ]
369 then
370 w_managed
3718simandl elif [ "a$wl_mode" = "aAd-Hoc" ]
372 then
373 w_managed
3742simandl elif [ "a$wl_mode" = "aMaster" ]
375 then
376 w_master
377 else
378 echo $wl_iface $wlm_no_managed_or_master
379 echo
380 fi
381}
382 
383######################################################################
38411simandlw_version()
385{
386 echo wifimon $wl_version
387 exit 0
388}
389######################################################################
3905simandlw_help()
391{
3923simandl echo Pouziti: wifimon [param]
393 echo param:
39411simandl echo -v vypise verzi
3955simandl echo -html generovani html stranky
39613simandl echo -col barevny vypis na obrazovku
3975simandl echo -once vypsani jen jednoho vypisu a pak program skonci
398 echo -oneline vypsani klientu na jednu linku
39915simandl echo -threeline vypsani klienta na trech radcich
400 echo -rxtxoff vypnuti zobrazeni objemu prenesenych dat klienta
401 echo -macoff vypnuti zobrazeni MAC adres
40213simandl echo -ppkts vypsani procentniho pomeru 1M, 2M, 5.5M a 11M paketu pro jednotlive klienty
403 echo -pkts vypsani poctu 1M, 2M, 5.5M a 11M paketu pro jednotlive klienty
4045simandl echo -wlan0 -wlan1 -wlan2 vypise jen uvedene karty a to v danem poctu a poradi
4053simandl echo bez parametru cyklicky vypis na obrazovku
4065simandl exit 0
407}
408######################################################################
409######################################################################
4102simandl 
4115simandlwl_unknown=""
412wl_cnt=1
413wcm_clear=1
414wcm_once=0
41511simandlwcm_col=0
4165simandlwcm_oneline=0
41715simandlwcm_threeline=0
4185simandlwcm_html=0
41915simandlwcm_rxtx=1
42013simandlwcm_ppkts=0
421wcm_pkts=0
4225simandlwcm_ifc=""
42315simandlwcm_macoff=0
4245simandl 
4256simandl# parsing input parameters
4265simandlwhile [ "a$1" != "a" ]
427do
428 case $1 in
42911simandl -v)
430 w_version
431 ;;
4325simandl -help)
433 w_help
434 ;;
435 -once)
436 wcm_once=1
437 shift
438 ;;
439 -oneline)
440 wcm_oneline=1
441 shift
442 ;;
44315simandl -threeline)
444 wcm_threeline=1
445 shift
446 ;;
44711simandl -col)
448 wcm_col=1
4495simandl shift
450 ;;
451 -html)
452 wcm_html=1
453 shift
454 ;;
45515simandl -rxtxoff)
456 wcm_rxtx=0
457 shift
458 ;;
45913simandl -ppkts)
460 wcm_ppkts=1
461 shift
462 ;;
463 -pkts)
464 wcm_pkts=1
465 shift
466 ;;
46715simandl -macoff)
468 wcm_macoff=1
469 shift
470 ;;
4715simandl *)
472 wl_flg=0
473 for wl_iface in `ls $wl_hostap`
474 do
475 if [ "a-$wl_iface" = "a$1" ]
476 then
477 wcm_ifc="$wcm_ifc $wl_iface"
478 wl_flg=1
479 fi
480 done
481 if [ $wl_flg -eq 0 ]
482 then
483 wl_unknown="$wl_unknown$1 "
484 fi
485 shift
486 esac
487done
488 
4896simandl# printing the list of bad parameters (if there are some)
4905simandlif [ "a$wl_unknown" != "a" ]
491then
492 echo "$wlm_unknown $wl_unknown"
493 w_help
494fi
495 
4966simandl# if no interface is selected then all available are choosen
4975simandlif [ "a$wcm_ifc" = "a" ]
498then
499 wcm_ifc=`ls $wl_hostap`
500fi
501 
5026simandl# setting for old and last same value to avoid double clear after start
503wl_numcllast=0
504wl_numclold=0
505for wl_iface in $wcm_ifc
506do
507 wl_numcl=`ls $wl_hostap$wl_iface | grep -c 00`
508 wl_numcllast=$(($wl_numcllast + $wl_numcl))
509done
510wl_numclold=$wl_numcllast
511 
51211simandlif [ $wcm_col -eq 0 ]
5136simandlthen
514 w_bw
51511simandlelse
51615simandl if [ $wcm_html -eq 1 ]
517 then
518 w_colh
519 else
520 w_col
521 fi
5226simandlfi
523 
52413simandlif [ $wcm_html -eq 1 ]
525then
526 [ $wcm_once -eq 1 ] && echo $wl_header || echo $wl_header_refresh
527 for wl_iface in $wcm_ifc
528 do
529 w_iface
530 done
531 echo $wl_footer
532 exit 0
533fi
534 
53515simandl#this is main loop and it will be executed forever
5366simandlwhile [ 1 ]
5375simandl do
53814simandl 
539 # when the number of associated klients has changed we will set for clear screen
5405simandl if [ $wl_numcllast -ne $wl_numclold ]
541 then
542 wl_numclold=$wl_numcllast
543 wcm_clear=1
544 fi
54514simandl 
546 #if it is set for clear screen we will do it except we produce single report
547 if [ $wcm_clear -eq 1 -a $wcm_once -eq 0 ]
5485simandl then
54914simandl echo -n $wl_clrcmde
5505simandl wcm_clear=0
551 fi
552 wl_numcllast=0
55311simandl 
55414simandl #for cyclic report we are trying to set cursor to the top left screen corner
555 if [ $wcm_once -eq 0 ]
556 then
557 echo -n $wl_tptcmde
558 fi
559 
560 #make report for all desired interfaces
56113simandl for wl_iface in $wcm_ifc
562 do
563 w_iface
564 done
565 
56614simandl #when a single report is needed than we are exiting
5675simandl if [ $wcm_once -eq 1 ]
568 then
569 exit 0
570 fi
571 sleep 1
5726simandldone
5735simandl 
574exit 0
575 

Powered by WebSVN 2.2.1