jablonka.czprosek.czf

wifimon

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

 

Line No. Rev Author Line
12simandl#!/bin/bash
23simandl# authors : Petr Simandl www.simandl.cz
314simandl# : Fyzik, Covex, Tydyt
4# release date : 05/10/2003
52simandl# name : wifimon
6# description : hostap powered wifi card monitoring
7# license : GPL
8 
915simandlwl_version="0.5.2"
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"
2616simandl#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######################################################################
26416simandlw_managed() {
265 echo $wl_iwctxt | $wl_awkcmd '{print $1,$3,$4,$5" "}'
26614simandl 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 
268 if [ $wcm_macoff -eq 1 ]
269 then
27016simandl echo $wl_iwctxt | $wl_awkcmd '{print $6""$7,$12""$13" "}'
27115simandl else
27216simandl echo $wl_iwctxt | $wl_awkcmd '{print $10,$6""$7,$12""$13" "}'
27315simandl fi
274 
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()
28916simandl{
290 if [ $wcm_oneline -eq 0 ]
2915simandl then
29214simandl echo $wl_iwctxt | $wl_awkcmd '{print $1,$3,$4,$5" "}'
29315simandl if [ $wcm_macoff -eq 1 ]
294 then
29516simandl echo $wl_iwctxt | $wl_awkcmd '{print $6""$7,$12""$13" "}'
29615simandl else
29716simandl echo $wl_iwctxt | $wl_awkcmd '{print $6""$7,$10,$12""$13" "}'
29815simandl fi
2995simandl else
30016simandl echo $wl_iwctxt | $wl_awkcmd '{print $1,$4,$5,$6""$7,$12""$13" "}' | sed 's/ [^": ]*:/ /g'
3015simandl fi
3022simandl wl_numcl=`ls $wl_hostap$wl_iface | grep -c 00`
303 echo $wlm_number_of_clients $wl_numcl
30413simandl 
3055simandl wl_numcllast=$(($wl_numcllast + $wl_numcl))
30613simandl 
3073simandl for wl_mac in `ls $wl_hostap$wl_iface | grep 00 `
3082simandl do
30911simandl wl_macparam=`cat $wl_hostap$wl_iface/$wl_mac | grep -E 'last_rx|last_tx' | sed 's/last_//g'`
31016simandl wl_jiffies=`cat $wl_hostap$wl_iface/$wl_mac | grep 'jiffies'`
311 wl_signal=`echo $wl_macparam | $wl_awkcmd '{print $6}' | sed 's/signal=//g'`
31214simandl wl_silence=`echo $wl_macparam | $wl_awkcmd '{print $4}' | sed 's/silence=//g'`
31316simandl wl_rate=`echo $wl_macparam | $wl_awkcmd '{print $8}'`
31411simandl wl_cnt=$(($wl_signal - $wl_silence))
31514simandl wl_ipc=`cat $wl_arp | grep -i $wl_mac | $wl_awkcmd '{print $1}'` # IP adresa peeru z arp tabulky
31613simandl 
31714simandl wl_name=`cat $wl_dhcpcnf | grep -i $wl_mac | $wl_awkcmd '{print $2}'`
318 if [ "$wl_name" = "ethernet" ] || [ "$wl_name" = "" ]
319 then
320 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}'`
321 if [ "$wl_name" = "" ]
322 then
323 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}'`
324 wl_name=`echo $wl_name | $wl_awkcmd '{print$1}' `
325 fi
326 fi
32713simandl if [ $wcm_ppkts -eq 1 ] || [ $wcm_pkts -eq 1 ]
328 then
329 w_pkts
330 fi
331 
3325simandl if [ $wcm_oneline -eq 0 ]
333 then
33415simandl echo -n "${wlc_name}$wl_name${wlc_std} "
3355simandl echo -n "${wlc_ip}$wl_ipc${wlc_std} "
33615simandl if [ $wcm_macoff -eq 0 ]
337 then
338 echo -n "${wlc_mac}$wl_mac${wlc_std} "
339 fi
340 if [ $wcm_threeline -eq 1 ]
341 then
342 echo ""
343 echo -n " "
344 fi
345 echo -n "Signal ${wlc_sig}$wl_cnt${wlc_std} "
34616simandl echo -n "$wl_rate "
34715simandl if [ $wcm_rxtx -eq 0 ]
348 then
349 echo ""
350 else
35116simandl echo $wl_macparam | $wl_awkcmd '{printf $1,$2" "}'
352 echo " $wl_jiffies"
35315simandl fi
3545simandl w_bar
355 else
35615simandl if [ $wcm_macoff -eq 0 ]
357 then
358 echo -n "${wlc_mac}$wl_mac${wlc_std} "
359 fi
360 echo -n "${wlc_sig}$wl_cnt${wlc_std} "
36116simandl echo -n "$wl_name"
3625simandl w_bar
363 fi
3644simandl done
36511simandl 
366 echo
3672simandl} # w_master
368 
369######################################################################
370w_iface()
37113simandl{ wl_iwctxt=`$wl_iwccmd $wl_iface 2>/dev/null | grep -v 'Device|Some|Extension' | sed 's/ Nick/_Nick/'`
37214simandl wl_mode=`echo $wl_iwctxt | $wl_awkcmd '{print $5}' | sed 's/Mode://g'`
3732simandl if [ "a$wl_mode" = "aManaged" ]
374 then
375 w_managed
3768simandl elif [ "a$wl_mode" = "aAd-Hoc" ]
377 then
378 w_managed
3792simandl elif [ "a$wl_mode" = "aMaster" ]
380 then
381 w_master
382 else
383 echo $wl_iface $wlm_no_managed_or_master
384 echo
385 fi
386}
387 
388######################################################################
38911simandlw_version()
390{
391 echo wifimon $wl_version
392 exit 0
393}
394######################################################################
3955simandlw_help()
396{
3973simandl echo Pouziti: wifimon [param]
398 echo param:
39911simandl echo -v vypise verzi
4005simandl echo -html generovani html stranky
40113simandl echo -col barevny vypis na obrazovku
4025simandl echo -once vypsani jen jednoho vypisu a pak program skonci
403 echo -oneline vypsani klientu na jednu linku
40415simandl echo -threeline vypsani klienta na trech radcich
405 echo -rxtxoff vypnuti zobrazeni objemu prenesenych dat klienta
406 echo -macoff vypnuti zobrazeni MAC adres
40713simandl echo -ppkts vypsani procentniho pomeru 1M, 2M, 5.5M a 11M paketu pro jednotlive klienty
408 echo -pkts vypsani poctu 1M, 2M, 5.5M a 11M paketu pro jednotlive klienty
4095simandl echo -wlan0 -wlan1 -wlan2 vypise jen uvedene karty a to v danem poctu a poradi
4103simandl echo bez parametru cyklicky vypis na obrazovku
4115simandl exit 0
412}
413######################################################################
414######################################################################
4152simandl 
4165simandlwl_unknown=""
417wl_cnt=1
418wcm_clear=1
419wcm_once=0
42011simandlwcm_col=0
4215simandlwcm_oneline=0
42215simandlwcm_threeline=0
4235simandlwcm_html=0
42415simandlwcm_rxtx=1
42513simandlwcm_ppkts=0
426wcm_pkts=0
4275simandlwcm_ifc=""
42815simandlwcm_macoff=0
4295simandl 
4306simandl# parsing input parameters
4315simandlwhile [ "a$1" != "a" ]
432do
433 case $1 in
43411simandl -v)
435 w_version
436 ;;
4375simandl -help)
438 w_help
439 ;;
440 -once)
441 wcm_once=1
442 shift
443 ;;
444 -oneline)
445 wcm_oneline=1
446 shift
447 ;;
44815simandl -threeline)
449 wcm_threeline=1
450 shift
451 ;;
45211simandl -col)
453 wcm_col=1
4545simandl shift
455 ;;
456 -html)
457 wcm_html=1
458 shift
459 ;;
46015simandl -rxtxoff)
461 wcm_rxtx=0
462 shift
463 ;;
46413simandl -ppkts)
465 wcm_ppkts=1
466 shift
467 ;;
468 -pkts)
469 wcm_pkts=1
470 shift
471 ;;
47215simandl -macoff)
473 wcm_macoff=1
474 shift
475 ;;
4765simandl *)
477 wl_flg=0
478 for wl_iface in `ls $wl_hostap`
479 do
480 if [ "a-$wl_iface" = "a$1" ]
481 then
482 wcm_ifc="$wcm_ifc $wl_iface"
483 wl_flg=1
484 fi
485 done
486 if [ $wl_flg -eq 0 ]
487 then
488 wl_unknown="$wl_unknown$1 "
489 fi
490 shift
491 esac
492done
493 
4946simandl# printing the list of bad parameters (if there are some)
4955simandlif [ "a$wl_unknown" != "a" ]
496then
497 echo "$wlm_unknown $wl_unknown"
498 w_help
499fi
500 
5016simandl# if no interface is selected then all available are choosen
5025simandlif [ "a$wcm_ifc" = "a" ]
503then
504 wcm_ifc=`ls $wl_hostap`
505fi
506 
5076simandl# setting for old and last same value to avoid double clear after start
508wl_numcllast=0
509wl_numclold=0
510for wl_iface in $wcm_ifc
511do
512 wl_numcl=`ls $wl_hostap$wl_iface | grep -c 00`
513 wl_numcllast=$(($wl_numcllast + $wl_numcl))
514done
515wl_numclold=$wl_numcllast
516 
51711simandlif [ $wcm_col -eq 0 ]
5186simandlthen
519 w_bw
52011simandlelse
52115simandl if [ $wcm_html -eq 1 ]
522 then
523 w_colh
524 else
525 w_col
526 fi
5276simandlfi
528 
52913simandlif [ $wcm_html -eq 1 ]
530then
531 [ $wcm_once -eq 1 ] && echo $wl_header || echo $wl_header_refresh
532 for wl_iface in $wcm_ifc
533 do
534 w_iface
535 done
536 echo $wl_footer
537 exit 0
538fi
539 
54015simandl#this is main loop and it will be executed forever
5416simandlwhile [ 1 ]
5425simandl do
54314simandl 
544 # when the number of associated klients has changed we will set for clear screen
5455simandl if [ $wl_numcllast -ne $wl_numclold ]
546 then
547 wl_numclold=$wl_numcllast
548 wcm_clear=1
549 fi
55014simandl 
551 #if it is set for clear screen we will do it except we produce single report
552 if [ $wcm_clear -eq 1 -a $wcm_once -eq 0 ]
5535simandl then
55414simandl echo -n $wl_clrcmde
5555simandl wcm_clear=0
556 fi
557 wl_numcllast=0
55811simandl 
55914simandl #for cyclic report we are trying to set cursor to the top left screen corner
560 if [ $wcm_once -eq 0 ]
561 then
562 echo -n $wl_tptcmde
563 fi
564 
565 #make report for all desired interfaces
56613simandl for wl_iface in $wcm_ifc
567 do
568 w_iface
569 done
570 
57114simandl #when a single report is needed than we are exiting
5725simandl if [ $wcm_once -eq 1 ]
573 then
574 exit 0
575 fi
576 sleep 1
5776simandldone
5785simandl 
579exit 0
580 

Powered by WebSVN 2.2.1