jablonka.czprosek.czf

wifimon

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

 

Line No. Rev Author Line
12simandl#!/bin/bash
23simandl# authors : Petr Simandl www.simandl.cz
339unreal# : Fyzik, Covex, Tydyt, Thunder.m, Unreal][
4# release date : 19/04/2012
52simandl# name : wifimon
621simandl# description : hostap and madwifi powered card monitoring
72simandl# license : GPL
821simandl######################################################################
92simandl 
1039unrealwl_version="0.5.7pre10"
1111simandl 
1221simandl######################################################################
13#custom settings
14 
1529simandlPATH=$PATH:$HOME/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
1613simandl 
1730simandlwl_wlancf=`which wlanconfig 2>/dev/null `
18wl_iwccmd=`which iwconfig 2>/dev/null`
19wl_iwlcmd=`which iwlist 2>/dev/null`
20wl_ifccmd=`which ifconfig 2>/dev/null`
21wl_hnmcmd=`which hostname 2>/dev/null`
22wl_awkcmd=`which awk 2>/dev/null`
2314simandl 
24wl_tptcmde=""
25wl_clrcmde=""
26 
2719simandlwl_sysdev="/proc/sys/dev/"
2814simandlwl_hostap="/proc/net/hostap/"
2927simandlwl_madwifi="/proc/net/madwifi/"
3014simandlwl_wireless="/proc/net/wireless"
31wl_arp="/proc/net/arp"
32wl_dhcpcnf="/etc/dhcpd.conf"
3330simandlwl_dhcplss="/var/lib/dhcpd/dhcpd.leases"
3417simandl# wl_dhcpcnf="/etc/dhcp3/dhcpd.conf"
35# wl_dhcplss="/var/lib/dhcp3/dhcpd.leases"
3614simandl 
3721simandlwl_header_refresh="<html><head><meta HTTP-EQUIV=\"Refresh\" CONTENT=\"15\"><title>Wifimon @ `$wl_hnmcmd`</title></head><body BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\"><pre>"
38wl_header="<html><head><title>Wifimon @ `$wl_hnmcmd`</title></head><body BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\"><pre>"
39wl_footer="</pre></body></html>"
4014simandl 
4121simandlwlm_no_managed_or_master=" neni ani Master ani Managed..."
4236simandlwlm_no_managed=" neni Managed takze neskenuju..."
43wlm_scan=" sken"
4421simandlwlm_number_of_clients="Pocet asociovanych klientu : "
45wlm_unknown="Nezname parametry nebo neplatne jmeno rozhrani : "
46#wlm_no_managed_or_master=" is not Master or Managed..."
47#wlm_number_of_clients="Number of associated clients : "
48 
49wlch_signal="="
50wlch_noise="*"
51 
52######################################################################
53#testing basic setings
54 
5512simandlif [ "$wl_iwccmd x" = " x" ]
56 then
57 echo "iwconfig not found"
58 exit 1
59fi
602simandl 
6121simandlif [ "$wl_iwlcmd x" = " x" ]
62 then
63 echo "iwlist not found"
64 exit 1
65fi
66 
6714simandlif [ "$wl_ifccmd x" = " x" ]
68 then
69 echo "ifconfig not found"
70 exit 1
71fi
724simandl 
7314simandlif [ "$wl_hnmcmd x" = " x" ]
74 then
75 echo "hostname not found"
76 exit 1
77fi
78 
79if [ "$wl_awkcmd x" = " x" ]
80 then
81 echo "awk not found"
82 exit 1
83fi
84 
85if [ -e $wl_wireless ]
86 then
87 wl_nop=1
88 else
89 echo "$wl_wireless not found"
90 exit 1
91fi
92 
93if [ -e $wl_arp ]
94 then
95 wl_nop=1
96 else
97 echo "$wl_arp not found"
98 exit 1
99fi
100 
10122simandl#dhcp support
102#if not found trying to set alternative location
103if [ ! -f $wl_dhcpcnf ]; then
104 wl_dhcpcnf="/etc/dhcp3/dhcpd.conf"
105fi
106 
107if [ ! -f $wl_dhcplss ]; then
108 wl_dhcplss="/var/lib/dhcp3/dhcpd.leases"
109fi
110 
111#if not found a message is printed and /dev/null is used instead
11214simandlif [ -e $wl_dhcpcnf ]
113 then
114 wl_nop=1
115 else
116 echo "$wl_dhcpcnf not found"
117 wl_dhcpcnf="/dev/null"
118fi
119 
12030simandlif [ ! -e $wl_dhcplss ]
12114simandl then
122 echo "$wl_dhcplss not found"
123 wl_dhcplss="/dev/null"
124fi
12521simandl######################################################################
12614simandl 
12724simandlif [ -d ${wl_hostap}wlan0 ]
12821simandl then
129 wlf_hostap=1
130 else
131# echo "${wl_hostap}wlan0 not found"
132 wlf_hostap=0
133fi
1347simandl 
13527simandlif [ -d ${wl_sysdev}ath ]
13621simandl then
137 wlf_madwifi=1
138 else
139# echo "${wl_sysdev}ath0 not found"
140 wlf_madwifi=0
141fi
1427simandl 
14329simandlwlf_wlancf=1
144if [ "$wl_wlancf x" = " x" ]
145 then
146 wlf_wlancf=0
147# echo "wlanconfig not found"
148# exit 1
149fi
150 
15121simandlif [ "$wlf_hostap" -eq 0 ] && [ "$wlf_madwifi" -eq 0 ]
152 then
15324simandl echo "${wl_hostap}wlan0 not found"
154 echo "${wl_sysdev}ath0 not found"
15521simandl exit 1
156fi
15711simandl 
15829simandl 
1592simandl######################################################################
16021simandl# procedures
161######################################################################
16211simandlw_col()
16310simandl{
16415simandlwlc_red=`tput setaf 1` # ruda (Red)
165wlc_green=`tput setaf 2` # zelena (Lime)
166wlc_brown=`tput setaf 3` # zluta (Yellow)
167wlc_blue=`tput setaf 4` # modra (Blue)
168wlc_magenta=`tput setaf 5` # fialova (Fuchsia)
169wlc_lblue=`tput setaf 6` # svetle modra (Aqua)
170wlc_grey=`tput setaf 7` # bila (White)
17111simandlwlc_std=`tput sgr0`
172 
17315simandlwlc_pkts=$wlc_red # Rx,Tx info color
17411simandlwlc_ip=$wlc_lblue # ip address color
175wlc_mac=$wlc_magenta # mac address color
17615simandlwlc_name=$wlc_magenta # host name color
17711simandlwlc_sig=$wlc_red # signal number color
178wlc_bar=$wlc_green # signal bar color
17915simandlwlc_noise=$wlc_red # Signal noise color
18010simandl}
181######################################################################
18215simandlw_colh()
183{
184 wlh_pkts="Olive" # signal number color html
185 wlh_ip="Blue" # ip address color html
186 wlh_mac="Fuchsia" # mac address color html
187 wlh_name="Fuchsia" # Host name color html
188 wlh_sig="Red" # signal number color html
189 wlh_bar="Lime" # signal bar color html
190 wlh_noise="Red" # Signal noise color html
191 
192 wlc_pkts="<font color=\"$wlh_pkts\">"
193 wlc_ip="<font color=\"$wlh_ip\">"
194 wlc_mac="<font color=\"$wlh_mac\">"
195 wlc_name="<font color=\"$wlh_name\">"
196 wlc_sig="<font color=\"$wlh_sig\">"
197 wlc_bar="<font color=\"$wlh_bar\">"
198 wlc_noise="<font color=\"$wlh_noise\">"
199 wlc_std="</font>"
200}
201######################################################################
2024simandlw_bw()
203{
20415simandl wlc_pkts=""
2056simandl wlc_ip=""
206 wlc_mac=""
207 wlc_sig=""
208 wlc_bar=""
20915simandl wlc_noise=""
2106simandl wlc_std=""
2114simandl}
212######################################################################
2132simandlw_bar()
214{
21511simandl wl_neg=`expr $wl_cnt \< 0 `
216 if [ "$wl_neg" -eq 1 ]
217 then
21815simandl echo -n "${wlc_noise}"
21911simandl wl_cnt=$(($wl_cnt * -1 ))
220 wl_bar=$wlch_noise
221 else
22215simandl echo -n "${wlc_bar}"
22311simandl wl_bar=$wlch_signal
224 fi
2252simandl until [ "$wl_cnt" -eq -1 ]
226 do
22711simandl echo -n "$wl_bar"
2282simandl wl_cnt=$(($wl_cnt - 1 ))
229 done
230 printf " \n"
2316simandl echo -n "${wlc_std}"
23211simandl# tput sgr0
2332simandl} # w_bar
234 
235######################################################################
23613simandlw_pkts()
237{
238 wl_macpkts=`cat $wl_hostap$wl_iface/$wl_mac | grep -E 'rx\[|tx\[' | sed 's/=/ /g'`
23914simandl wl_nt1=`echo $wl_macpkts | $wl_awkcmd '{print $2}'`
240 wl_nt2=`echo $wl_macpkts | $wl_awkcmd '{print $4}'`
241 wl_nt5=`echo $wl_macpkts | $wl_awkcmd '{print $6}'`
242 wl_nt11=`echo $wl_macpkts | $wl_awkcmd '{print $8}'`
243 wl_nr1=`echo $wl_macpkts | $wl_awkcmd '{print $10}'`
244 wl_nr2=`echo $wl_macpkts | $wl_awkcmd '{print $12}'`
245 wl_nr5=`echo $wl_macpkts | $wl_awkcmd '{print $14}'`
246 wl_nr11=`echo $wl_macpkts | $wl_awkcmd '{print $16}'`
24713simandl 
248 if [ $wcm_ppkts -eq 1 ]
249 then
250 wl_pksize=$((98))
251 wl_nt=$(($wl_nt1 + $wl_nt2 + wl_nt5 + wl_nt11))
252 if [ "$wl_nt1" -eq 0 ]
253 then
254 wl_nt1n="00"
255 else
256 wl_nt1n=$(($wl_pksize * $wl_nt1 / $wl_nt + 1))
257 [ "$wl_nt1n" -lt 10 ] && wl_nt1n="0"$wl_nt1n
258 fi
259 if [ "$wl_nt2" -eq 0 ]
260 then
261 wl_nt2n="00"
262 else
263 wl_nt2n=$(($wl_pksize * $wl_nt2 / $wl_nt + 1))
264 [ "$wl_nt2n" -lt 10 ] && wl_nt2n="0"$wl_nt2n
265 fi
266 if [ "$wl_nt5" -eq 0 ]
267 then
268 wl_nt5n="00"
269 else
270 wl_nt5n=$(($wl_pksize * $wl_nt5 / $wl_nt + 1))
271 [ "$wl_nt5n" -lt 10 ] && wl_nt5n="0"$wl_nt5n
272 fi
273 if [ "$wl_nt11" -eq 0 ]
274 then
275 wl_nt11n="00"
276 else
277 wl_nt11n=$(($wl_pksize * $wl_nt11 / $wl_nt + 1))
278 [ "$wl_nt11n" -lt 10 ] && wl_nt11n="0"$wl_nt11n
279 fi
280 wl_nr=$((1 + $wl_nr1 + $wl_nr2 + wl_nr5 + wl_nr11))
281 if [ "$wl_nr1" -eq 0 ]
282 then
283 wl_nr1n="00"
284 else
285 wl_nr1n=$(($wl_pksize * $wl_nr1 / $wl_nr + 1))
286 [ "$wl_nr1n" -lt 10 ] && wl_nr1n="0"$wl_nr1n
287 fi
288 if [ "$wl_nr2" -eq 0 ]
289 then
290 wl_nr2n="00"
291 else
292 wl_nr2n=$(($wl_pksize * $wl_nr2 / $wl_nr + 1))
293 [ "$wl_nr2n" -lt 10 ] && wl_nr2n="0"$wl_nr2n
294 fi
295 if [ "$wl_nr5" -eq 0 ]
296 then
297 wl_nr5n="00"
298 else
299 wl_nr5n=$(($wl_pksize * $wl_nr5 / $wl_nr + 1))
300 [ "$wl_nr5n" -lt 10 ] && wl_nr5n="0"$wl_nr5n
301 fi
302 if [ "$wl_nr11" -eq 0 ]
303 then
304 wl_nr11n="00"
305 else
306 wl_nr11n=$(($wl_pksize * $wl_nr11 / $wl_nr + 1))
307 [ "$wl_nr11n" -lt 10 ] && wl_nr11n="0"$wl_nr11n
308 fi
30915simandl echo -n "Tx"${wlc_pkts} $wl_nt1n $wl_nt2n $wl_nt5n $wl_nt11n ${wlc_std}""
310 echo -n "Rx"${wlc_pkts} $wl_nr1n $wl_nr2n $wl_nr5n $wl_nr11n ${wlc_std}""
31113simandl fi
312 
313 [ $wcm_pkts -eq 1 ] && echo -n "Tx" $wl_nt1 $wl_nt2 $wl_nt5 $wl_nt11 "Rx" $wl_nr1 $wl_nr2 $wl_nr5 $wl_nr11 ""
314 
315} # w_pkts
316######################################################################
31717simandlw_managed()
318{ echo $wl_iwctxt | $wl_awkcmd '{print $1,$3,$4,$5" "}'
31924simandl 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
32015simandl 
32118simandl if [ $wcm_macoff -eq 0 ]
32215simandl then
32325simandl wl_mac=`echo -n $wl_iwctxt | $wl_awkcmd '{print $8}'`
32418simandl echo -n "${wlc_mac}$wl_mac${wlc_std} "
32515simandl fi
32626simandl echo $wl_iwctxt | $wl_awkcmd '{print $6,$10,$11,$12" "}'
32715simandl 
32824simandl wl_wtxt=`cat $wl_wireless | grep $wl_iface | $wl_awkcmd '{print $3,$4,$5}' | sed 's/\.//g'`
32914simandl wl_quality=`echo $wl_wtxt | $wl_awkcmd '{print $1}'`
330 wl_signal=`echo $wl_wtxt | $wl_awkcmd '{print $2}'`
3312simandl wl_signal=$(($wl_signal - 256))
33214simandl wl_noise=`echo $wl_wtxt | $wl_awkcmd '{print $3}'`
3332simandl wl_noise=$(($wl_noise - 256))
3345simandl echo "Quality:${wlc_sig}$wl_quality${wlc_std}/92 Signal level:$wl_signal Noise level:$wl_noise "
3352simandl wl_cnt=$wl_quality
336 w_bar
337 echo
338} # w_managed
339 
340######################################################################
341w_master()
34217simandl{ if [ $wcm_oneline -eq 0 ]
34321simandl then
344 echo $wl_iwctxt | $wl_awkcmd '{print $1,$3,$4,$5" "}'
345 if [ $wcm_macoff -eq 1 ]
346 then
34729simandl echo $wl_iwctxt | $wl_awkcmd '{print $6,$10,$11,$12" "}'
34821simandl else
34929simandl echo $wl_iwctxt | $wl_awkcmd '{print $6,$8,$10,$11,$12" "}'
35021simandl fi
351 else
35226simandl echo $wl_iwctxt | $wl_awkcmd '{print $1,$4,$5,$6,$11,$12" "}' | sed 's/ [^": ]*:/ /g'
35321simandl fi
354 
355 if [ -d $wl_hostap$wl_iface ]
35615simandl then
35739unreal wl_numcl=`ls $wl_hostap$wl_iface | grep -c [0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]:`
358 wl_macs=`ls $wl_hostap$wl_iface | grep [0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]:`
3595simandl fi
36021simandl 
36127simandl if [ -d $wl_madwifi$wl_iface ]
36221simandl then
36339unreal wl_numcl=`$wl_wlancf $wl_iface list sta | grep -c ^[0-9a-fA-F][0-9a-fA-F]:`
36428simandl# wl_numcl=`cat $wl_madwifi$wl_iface/associated_sta | grep -c macaddr`
365# wl_macs=`cat $wl_madwifi$wl_iface/associated_sta | tr "<" "#" | tr ">" "#" | tr " " "#" | tr "\n" "#" | tr "m" "\n" `
36639unreal wl_macs=`$wl_wlancf $wl_iface list sta | grep ^[0-9a-fA-F][0-9a-fA-F]: | tr " " "#"`
36721simandl fi
36829simandl 
369 if [ -d $wl_sysdev$wl_iface ]
370 then
37139unreal wl_numcl=`$wl_iwlcmd $wl_iface peers | grep -c [0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]:`
37240unreal wl_macs=`$wl_iwlcmd $wl_iface peers | grep [0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]: | $wl_awkcmd '{print $1}'`
37329simandl fi
374 
3752simandl echo $wlm_number_of_clients $wl_numcl
37613simandl 
3775simandl wl_numcllast=$(($wl_numcllast + $wl_numcl))
37813simandl 
37921simandl for wl_mac in $wl_macs
3802simandl do
38121simandl if [ -d $wl_hostap$wl_iface ]
382 then
383 wl_macparam=`cat $wl_hostap$wl_iface/$wl_mac | grep -E 'last_rx|last_tx' | sed 's/last_//g'`
38422simandl wl_signal=`echo $wl_macparam | $wl_awkcmd '{print $6}' | sed 's/signal[=|:]//g'`
385 wl_silence=`echo $wl_macparam | $wl_awkcmd '{print $4}' | sed 's/silence[=|:]//g'`
38621simandl fi
387 
38827simandl if [ -d $wl_madwifi$wl_iface ]
38921simandl then
39028simandl wl_signal=`echo $wl_mac | tr "#" " " | $wl_awkcmd '{print $5}'`
391 wl_rxtx=`echo $wl_mac | tr "#" " " | $wl_awkcmd '{print "rate="$4" tx="$8" rx="$9}'`
39227simandl wl_silence="0"
39328simandl wl_mac=`echo $wl_mac | tr "#" " " | $wl_awkcmd '{print $1}'`
39421simandl fi
39529simandl 
396 if [ -d $wl_sysdev$wl_iface ]
397 then
398 wl_macparam=`$wl_iwlcmd $wl_iface peers | grep $wl_mac`
399 wl_signal=`echo $wl_macparam | $wl_awkcmd '{print $5}' | sed 's/level[=|:]//g'`
400 wl_silence=`echo $wl_macparam | $wl_awkcmd '{print $8}' | sed 's/level[=|:]//g'`
401 fi
402 
40311simandl wl_cnt=$(($wl_signal - $wl_silence))
40414simandl wl_ipc=`cat $wl_arp | grep -i $wl_mac | $wl_awkcmd '{print $1}'` # IP adresa peeru z arp tabulky
40513simandl 
40614simandl wl_name=`cat $wl_dhcpcnf | grep -i $wl_mac | $wl_awkcmd '{print $2}'`
407 if [ "$wl_name" = "ethernet" ] || [ "$wl_name" = "" ]
408 then
409 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}'`
410 if [ "$wl_name" = "" ]
411 then
41217simandl wl_name=`cat $wl_dhcplss | grep -i $wl_mac -A 2 | grep -i client-hostname | $wl_awkcmd '{print$2}'`
41314simandl wl_name=`echo $wl_name | $wl_awkcmd '{print$1}' `
414 fi
415 fi
41621simandl if [ $wcm_ppkts -eq 1 ] || [ $wcm_pkts -eq 1 ] && [ -d $wl_hostap$wl_iface ]
41713simandl then
418 w_pkts
419 fi
420 
4215simandl if [ $wcm_oneline -eq 0 ]
422 then
42315simandl echo -n "${wlc_name}$wl_name${wlc_std} "
4245simandl echo -n "${wlc_ip}$wl_ipc${wlc_std} "
42515simandl if [ $wcm_macoff -eq 0 ]
426 then
427 echo -n "${wlc_mac}$wl_mac${wlc_std} "
428 fi
429 if [ $wcm_threeline -eq 1 ]
430 then
431 echo ""
432 echo -n " "
433 fi
434 echo -n "Signal ${wlc_sig}$wl_cnt${wlc_std} "
435 if [ $wcm_rxtx -eq 0 ]
436 then
437 echo ""
438 else
43921simandl if [ -d $wl_hostap$wl_iface ]
440 then
44132simandl echo $wl_macparam | $wl_awkcmd '{print $1,$2" "}'
44221simandl fi
44328simandl if [ -d $wl_madwifi$wl_iface ]
444 then
44532simandl echo -n $wl_rxtx
446 echo ""
44728simandl fi
44832simandl# echo ""
44915simandl fi
4505simandl w_bar
451 else
45215simandl if [ $wcm_macoff -eq 0 ]
453 then
454 echo -n "${wlc_mac}$wl_mac${wlc_std} "
455 fi
456 echo -n "${wlc_sig}$wl_cnt${wlc_std} "
45717simandl echo -n "$wl_name "
4585simandl w_bar
459 fi
4604simandl done
46111simandl 
462 echo
4632simandl} # w_master
464 
465######################################################################
466w_iface()
46726simandl{ wl_iwctxt=`$wl_iwccmd $wl_iface 2>/dev/null | grep -v 'Device|Some|Extension' | sed 's/ dBm/dBm/' | sed 's/ GHz/GHz/' | sed 's/ Mb/Mb/' | sed 's/ Nick/_Nick/' | sed 's/Access Point/Access_Point/'`
46814simandl wl_mode=`echo $wl_iwctxt | $wl_awkcmd '{print $5}' | sed 's/Mode://g'`
4692simandl if [ "a$wl_mode" = "aManaged" ]
470 then
471 w_managed
4728simandl elif [ "a$wl_mode" = "aAd-Hoc" ]
473 then
474 w_managed
4752simandl elif [ "a$wl_mode" = "aMaster" ]
476 then
477 w_master
478 else
47924simandl echo $wl_iface $wlm_no_managed_or_master
4802simandl echo
481 fi
482}
483 
484######################################################################
48536simandlw_scan()
486{ $wl_scancmd 2>/dev/null | awk '
487 BEGIN {
488 nocompleted = 1;
489 }
490 
491 / - Address:/ {
492 MAC = $5;
493 Cell = $2;
494 }
495 
496 /ESSID:/ {
497 sub("ESSID:", "");
498 gsub("\"", "");
499 ESSID = $1;
500 }
501 
502 /Frequency:/ {
503 sub("Frequency:", "");
504 Frequency = $1;
505 sub(")", "");
506 Channel = $4;
507 }
508 
509 /Quality=/ {
510 sub("Quality=", "");
511 sub("/", " ");
512 Quality = $1;
513 nocompleted = 0;
514 }
515 
516 (nocompleted == 0) {
51737simandl printf "%s \t %s \t %s ", Frequency, Quality, MAC;
51838simandl if (Quality > 127) {
519 Quality = 256 - Quality
520 for (i = 1; i <= Quality; i++)
521 printf "*"; }
522 else {
523 for (i = 1; i <= Quality; i++)
524 printf "#"; }
52536simandl print " " ESSID;
526 }
527 
528 { nocompleted++; }
529' | sort -g | uniq
530 
531}
532 
533######################################################################
534w_scaniface()
535{ wl_iwctxt=`$wl_iwccmd $wl_iface 2>/dev/null | grep -v 'Device|Some|Extension' | sed 's/ dBm/dBm/' | sed 's/ GHz/GHz/' | sed 's/ Mb/Mb/' | sed 's/ Nick/_Nick/' | sed 's/Access Point/Access_Point/'`
536 wl_mode=`echo $wl_iwctxt | $wl_awkcmd '{print $5}' | sed 's/Mode://g'`
537 if [ "a$wl_mode" = "aManaged" ]
538 then
539 echo $wl_iface $wlm_scan
540 wl_scancmd="$wl_iwlcmd $wl_iface scan"
541 w_scan
542 elif [ "a$wl_mode" = "aAd-Hoc" ]
543 then
544 wl_scancmd="$wl_iwlcmd $wl_iface scan"
545 echo $wl_iface $wlm_scan
546 w_scan
547 elif [ "a$wl_mode" = "aMaster" ]
548 then
549 echo $wl_iface $wlm_no_managed
550 echo
551 else
552 echo $wl_iface $wlm_no_managed_or_master
553 echo
554 fi
555}
556 
557######################################################################
55811simandlw_version()
559{
560 echo wifimon $wl_version
561 exit 0
562}
563######################################################################
5645simandlw_help()
565{
56621simandl echo Monitorovani wifi karet pouzivajicich hostap nebo madwifi ovladace
5673simandl echo Pouziti: wifimon [param]
568 echo param:
56911simandl echo -v vypise verzi
5705simandl echo -html generovani html stranky
57113simandl echo -col barevny vypis na obrazovku
5725simandl echo -once vypsani jen jednoho vypisu a pak program skonci
573 echo -oneline vypsani klientu na jednu linku
57415simandl echo -threeline vypsani klienta na trech radcich
57521simandl echo -macoff vypnuti zobrazeni MAC adres
576 echo -wlan0 -ath0 -wlan2 vypise jen uvedene karty a to v danem poctu a poradi
577 echo nasledujici parametry ovlivnuji jen karty s hostap:
57815simandl echo -rxtxoff vypnuti zobrazeni objemu prenesenych dat klienta
57913simandl echo -ppkts vypsani procentniho pomeru 1M, 2M, 5.5M a 11M paketu pro jednotlive klienty
580 echo -pkts vypsani poctu 1M, 2M, 5.5M a 11M paketu pro jednotlive klienty
58136simandl echo -scan vypsani naskenovanych AP
582 echo "-scanfromfile <file_name> vypsani naskenovanych AP z textoveho souboru (vypis iwlist athX scan)"
5833simandl echo bez parametru cyklicky vypis na obrazovku
5845simandl exit 0
585}
586######################################################################
587######################################################################
5882simandl 
5895simandlwl_unknown=""
590wl_cnt=1
591wcm_clear=1
592wcm_once=0
59324simandlwcm_col=0
5945simandlwcm_oneline=0
59515simandlwcm_threeline=0
5965simandlwcm_html=0
59715simandlwcm_rxtx=1
59813simandlwcm_ppkts=0
599wcm_pkts=0
6005simandlwcm_ifc=""
60115simandlwcm_macoff=0
60236simandlwcm_scan=0
603wcm_scanff=0
6045simandl 
6056simandl# parsing input parameters
6065simandlwhile [ "a$1" != "a" ]
607do
608 case $1 in
60911simandl -v)
610 w_version
611 ;;
6125simandl -help)
613 w_help
614 ;;
615 -once)
616 wcm_once=1
617 shift
618 ;;
619 -oneline)
620 wcm_oneline=1
621 shift
622 ;;
62315simandl -threeline)
624 wcm_threeline=1
625 shift
626 ;;
62711simandl -col)
62824simandl wcm_col=1
6295simandl shift
630 ;;
631 -html)
632 wcm_html=1
633 shift
634 ;;
63515simandl -rxtxoff)
636 wcm_rxtx=0
637 shift
638 ;;
63913simandl -ppkts)
640 wcm_ppkts=1
641 shift
642 ;;
643 -pkts)
644 wcm_pkts=1
645 shift
646 ;;
64715simandl -macoff)
648 wcm_macoff=1
649 shift
650 ;;
65136simandl -scan)
652 wcm_scan=1
653 shift
654 ;;
655 -scanfromfile)
656 wcm_scanff=1
657 wl_scanfn=$2
658 shift
659 shift
660 ;;
6615simandl *)
662 wl_flg=0
66319simandl#wlan check
66421simandl if [ $wlf_hostap -eq 1 ]
6655simandl then
66621simandl for wl_iface in `ls $wl_hostap`
667 do
66824simandl if [ "a-$wl_iface" = "a$1" ]
66921simandl then
670 wcm_ifc="$wcm_ifc $wl_iface"
671 wl_flg=1
672 fi
673 done
674 fi
67519simandl# ath check
67621simandl if [ $wlf_madwifi -eq 1 ]
67719simandl then
67827simandl for wl_iface in `ls $wl_madwifi | grep "ath[0-9]"`
67921simandl do
68024simandl if [ "a-$wl_iface" = "a$1" ]
68121simandl then
682 wcm_ifc="$wcm_ifc $wl_iface"
683 wl_flg=1
684 fi
685 done
68631simandl for wl_iface in `ls $wl_sysdev | grep "ath[0-9]"`
687 do
688 if [ "a-$wl_iface" = "a$1" ]
689 then
690 wcm_ifc="$wcm_ifc $wl_iface"
691 wl_flg=1
692 fi
693 done
69421simandl fi
6955simandl if [ $wl_flg -eq 0 ]
69621simandl then
697 wl_unknown="$wl_unknown$1 "
6985simandl fi
699 shift
700 esac
701done
702 
7036simandl# printing the list of bad parameters (if there are some)
7045simandlif [ "a$wl_unknown" != "a" ]
705then
706 echo "$wlm_unknown $wl_unknown"
707 w_help
708fi
70929simandl 
7106simandl# if no interface is selected then all available are choosen
7115simandlif [ "a$wcm_ifc" = "a" ]
712then
71321simandl if [ $wlf_hostap -eq 1 ]
714 then
715 wcm_ifc=`ls $wl_hostap `
716 fi
717 if [ $wlf_madwifi -eq 1 ]
718 then
71929simandl wcm_ifc=`echo $wcm_ifc ; ls $wl_sysdev | grep "ath[0-9]" ; ls $wl_madwifi | grep "ath[0-9]"`
72021simandl fi
7215simandlfi
722 
72336simandl# in case of scan request we do all scans
724 if [ $wcm_scan -eq 1 ]
725 then
726 for wl_iface in $wcm_ifc
727 do
728 w_scaniface
729 done
730 exit 0
731 fi
732 
733# in case of scan from file request we get the file and process it
734 if [ $wcm_scanff -eq 1 ]
735 then
736 echo $wl_scanfn $wlm_scan
737 wl_scancmd="cat $wl_scanfn"
738 w_scan
739 exit 0
740 fi
741 
7426simandl# setting for old and last same value to avoid double clear after start
743wl_numcllast=0
744wl_numclold=0
745for wl_iface in $wcm_ifc
746do
74721simandl if [ -d $wl_hostap$wl_iface ]
748 then
749 wl_numcl=`ls $wl_hostap$wl_iface | grep -c 00`
750 wl_numcllast=$(($wl_numcllast + $wl_numcl))
751 fi
75227simandl if [ -d $wl_madwifi$wl_iface ]
75321simandl then
75432simandl wl_mode=`$wl_iwccmd $wl_iface 2>/dev/null | grep Mode | $wl_awkcmd '{print $1}' | sed 's/Mode://g'`
75521simandl if [ "a$wl_mode" = "aMaster" ]
756 then
75732simandl wl_numcl=`$wl_wlancf $wl_iface list sta 2>/dev/null | grep -c ^[0..9]`
75821simandl wl_numcllast=$(($wl_numcllast + $wl_numcl))
759 fi
760 fi
76129simandl if [ -d $wl_sysdev$wl_iface ]
762 then
76333simandl wl_mode=`$wl_iwccmd $wl_iface 2>/dev/null | grep Mode | $wl_awkcmd '{print $1}' | sed 's/Mode://g'`
76429simandl if [ "a$wl_mode" = "aMaster" ]
765 then
766 wl_numcl=`$wl_iwlcmd $wl_iface peers | grep -c 00`
767 wl_numcllast=$(($wl_numcllast + $wl_numcl))
768 fi
769 fi
770 
7716simandldone
772wl_numclold=$wl_numcllast
773 
77411simandlif [ $wcm_col -eq 0 ]
7756simandlthen
776 w_bw
77711simandlelse
77815simandl if [ $wcm_html -eq 1 ]
779 then
780 w_colh
781 else
782 w_col
783 fi
7846simandlfi
785 
78613simandlif [ $wcm_html -eq 1 ]
787then
788 [ $wcm_once -eq 1 ] && echo $wl_header || echo $wl_header_refresh
789 for wl_iface in $wcm_ifc
790 do
791 w_iface
792 done
793 echo $wl_footer
794 exit 0
795fi
796 
79715simandl#this is main loop and it will be executed forever
7986simandlwhile [ 1 ]
7995simandl do
80014simandl 
801 # when the number of associated klients has changed we will set for clear screen
8025simandl if [ $wl_numcllast -ne $wl_numclold ]
803 then
804 wl_numclold=$wl_numcllast
805 wcm_clear=1
806 fi
80714simandl 
808 #if it is set for clear screen we will do it except we produce single report
809 if [ $wcm_clear -eq 1 -a $wcm_once -eq 0 ]
8105simandl then
81114simandl echo -n $wl_clrcmde
8125simandl wcm_clear=0
813 fi
814 wl_numcllast=0
81511simandl 
81614simandl #for cyclic report we are trying to set cursor to the top left screen corner
817 if [ $wcm_once -eq 0 ]
818 then
819 echo -n $wl_tptcmde
820 fi
821 
822 #make report for all desired interfaces
82313simandl for wl_iface in $wcm_ifc
824 do
825 w_iface
826 done
827 
82814simandl #when a single report is needed than we are exiting
8295simandl if [ $wcm_once -eq 1 ]
830 then
831 exit 0
832 fi
833 sleep 1
8346simandldone
8355simandl 
83636simandlexit 0

Powered by WebSVN 2.2.1