jablonka.czprosek.czf

wifimon

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

 

Line No. Rev Author Line
12simandl#!/bin/bash
23simandl# authors : Petr Simandl www.simandl.cz
314simandl# : Fyzik, Covex, Tydyt
420simandl# release date : 09/09/2005
52simandl# name : wifimon
620simandl# description : hostap powered wifi card monitoring
72simandl# license : GPL
8 
920simandlwl_version="0.5.5pre1"
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 
2119simandlwl_sysdev="/proc/sys/dev/"
2214simandlwl_hostap="/proc/net/hostap/"
23wl_wireless="/proc/net/wireless"
24wl_arp="/proc/net/arp"
25wl_dhcpcnf="/etc/dhcpd.conf"
26wl_dhcplss="/var/lib/dhcp/dhcpd.leases"
2717simandl# wl_dhcpcnf="/etc/dhcp3/dhcpd.conf"
28# wl_dhcplss="/var/lib/dhcp3/dhcpd.leases"
2914simandl 
3020simandl#testing all settings
3114simandl 
3212simandlif [ "$wl_iwccmd x" = " x" ]
33 then
34 echo "iwconfig not found"
35 exit 1
36fi
372simandl 
3814simandlif [ "$wl_ifccmd x" = " x" ]
39 then
40 echo "ifconfig not found"
41 exit 1
42fi
434simandl 
4414simandlif [ "$wl_hnmcmd x" = " x" ]
45 then
46 echo "hostname not found"
47 exit 1
48fi
49 
50if [ "$wl_awkcmd x" = " x" ]
51 then
52 echo "awk not found"
53 exit 1
54fi
55 
5620simandlif [ -d $wl_hostap ]
57 then
58 wl_nop=1
59 else
60 echo "hostap not found"
61 exit 1
62fi
63 
6414simandlif [ -e $wl_wireless ]
65 then
66 wl_nop=1
67 else
68 echo "$wl_wireless not found"
69 exit 1
70fi
71 
72if [ -e $wl_arp ]
73 then
74 wl_nop=1
75 else
76 echo "$wl_arp not found"
77 exit 1
78fi
79 
80if [ -e $wl_dhcpcnf ]
81 then
82 wl_nop=1
83 else
84 echo "$wl_dhcpcnf not found"
85 wl_dhcpcnf="/dev/null"
86fi
87 
88if [ -e $wl_dhcplss ]
89 then
90 wl_nop=1
91 else
92 echo "$wl_dhcplss not found"
93 wl_dhcplss="/dev/null"
94fi
95 
9620simandlwl_header_refresh="<html><head><meta HTTP-EQUIV=\"Refresh\" CONTENT=\"15\"><title>Wifimon @ `$wl_hnmcmd`</title></head><body BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\"><pre>"
97wl_header="<html><head><title>Wifimon @ `$wl_hnmcmd`</title></head><body BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\"><pre>"
98wl_footer="</pre></body></html>"
997simandl 
10020simandlwlm_no_managed_or_master=" neni ani Master ani Managed..."
101wlm_number_of_clients="Pocet asociovanych klientu : "
102wlm_unknown="Nezname parametry nebo neplatne jmeno rozhrani : "
103#wlm_no_managed_or_master=" is not Master or Managed..."
104#wlm_number_of_clients="Number of associated clients : "
1057simandl 
10620simandlwlch_signal="="
107wlch_noise="*"
10811simandl 
1092simandl######################################################################
11011simandlw_col()
11110simandl{
11215simandlwlc_red=`tput setaf 1` # ruda (Red)
113wlc_green=`tput setaf 2` # zelena (Lime)
114wlc_brown=`tput setaf 3` # zluta (Yellow)
115wlc_blue=`tput setaf 4` # modra (Blue)
116wlc_magenta=`tput setaf 5` # fialova (Fuchsia)
117wlc_lblue=`tput setaf 6` # svetle modra (Aqua)
118wlc_grey=`tput setaf 7` # bila (White)
11911simandlwlc_std=`tput sgr0`
120 
12115simandlwlc_pkts=$wlc_red # Rx,Tx info color
12211simandlwlc_ip=$wlc_lblue # ip address color
123wlc_mac=$wlc_magenta # mac address color
12415simandlwlc_name=$wlc_magenta # host name color
12511simandlwlc_sig=$wlc_red # signal number color
126wlc_bar=$wlc_green # signal bar color
12715simandlwlc_noise=$wlc_red # Signal noise color
12810simandl}
129######################################################################
13015simandlw_colh()
131{
132 wlh_pkts="Olive" # signal number color html
133 wlh_ip="Blue" # ip address color html
134 wlh_mac="Fuchsia" # mac address color html
135 wlh_name="Fuchsia" # Host name color html
136 wlh_sig="Red" # signal number color html
137 wlh_bar="Lime" # signal bar color html
138 wlh_noise="Red" # Signal noise color html
139 
140 wlc_pkts="<font color=\"$wlh_pkts\">"
141 wlc_ip="<font color=\"$wlh_ip\">"
142 wlc_mac="<font color=\"$wlh_mac\">"
143 wlc_name="<font color=\"$wlh_name\">"
144 wlc_sig="<font color=\"$wlh_sig\">"
145 wlc_bar="<font color=\"$wlh_bar\">"
146 wlc_noise="<font color=\"$wlh_noise\">"
147 wlc_std="</font>"
148}
149######################################################################
1504simandlw_bw()
151{
15215simandl wlc_pkts=""
1536simandl wlc_ip=""
154 wlc_mac=""
155 wlc_sig=""
156 wlc_bar=""
15715simandl wlc_noise=""
1586simandl wlc_std=""
1594simandl}
160######################################################################
1612simandlw_bar()
162{
16311simandl wl_neg=`expr $wl_cnt \< 0 `
164 if [ "$wl_neg" -eq 1 ]
165 then
16615simandl echo -n "${wlc_noise}"
16711simandl wl_cnt=$(($wl_cnt * -1 ))
168 wl_bar=$wlch_noise
169 else
17015simandl echo -n "${wlc_bar}"
17111simandl wl_bar=$wlch_signal
172 fi
1732simandl until [ "$wl_cnt" -eq -1 ]
174 do
17511simandl echo -n "$wl_bar"
1762simandl wl_cnt=$(($wl_cnt - 1 ))
177 done
178 printf " \n"
1796simandl echo -n "${wlc_std}"
18011simandl# tput sgr0
1812simandl} # w_bar
182 
183######################################################################
18413simandlw_pkts()
185{
186 wl_macpkts=`cat $wl_hostap$wl_iface/$wl_mac | grep -E 'rx\[|tx\[' | sed 's/=/ /g'`
18714simandl wl_nt1=`echo $wl_macpkts | $wl_awkcmd '{print $2}'`
188 wl_nt2=`echo $wl_macpkts | $wl_awkcmd '{print $4}'`
189 wl_nt5=`echo $wl_macpkts | $wl_awkcmd '{print $6}'`
190 wl_nt11=`echo $wl_macpkts | $wl_awkcmd '{print $8}'`
191 wl_nr1=`echo $wl_macpkts | $wl_awkcmd '{print $10}'`
192 wl_nr2=`echo $wl_macpkts | $wl_awkcmd '{print $12}'`
193 wl_nr5=`echo $wl_macpkts | $wl_awkcmd '{print $14}'`
194 wl_nr11=`echo $wl_macpkts | $wl_awkcmd '{print $16}'`
19513simandl 
196 if [ $wcm_ppkts -eq 1 ]
197 then
198 wl_pksize=$((98))
199 wl_nt=$(($wl_nt1 + $wl_nt2 + wl_nt5 + wl_nt11))
200 if [ "$wl_nt1" -eq 0 ]
201 then
202 wl_nt1n="00"
203 else
204 wl_nt1n=$(($wl_pksize * $wl_nt1 / $wl_nt + 1))
205 [ "$wl_nt1n" -lt 10 ] && wl_nt1n="0"$wl_nt1n
206 fi
207 if [ "$wl_nt2" -eq 0 ]
208 then
209 wl_nt2n="00"
210 else
211 wl_nt2n=$(($wl_pksize * $wl_nt2 / $wl_nt + 1))
212 [ "$wl_nt2n" -lt 10 ] && wl_nt2n="0"$wl_nt2n
213 fi
214 if [ "$wl_nt5" -eq 0 ]
215 then
216 wl_nt5n="00"
217 else
218 wl_nt5n=$(($wl_pksize * $wl_nt5 / $wl_nt + 1))
219 [ "$wl_nt5n" -lt 10 ] && wl_nt5n="0"$wl_nt5n
220 fi
221 if [ "$wl_nt11" -eq 0 ]
222 then
223 wl_nt11n="00"
224 else
225 wl_nt11n=$(($wl_pksize * $wl_nt11 / $wl_nt + 1))
226 [ "$wl_nt11n" -lt 10 ] && wl_nt11n="0"$wl_nt11n
227 fi
228 wl_nr=$((1 + $wl_nr1 + $wl_nr2 + wl_nr5 + wl_nr11))
229 if [ "$wl_nr1" -eq 0 ]
230 then
231 wl_nr1n="00"
232 else
233 wl_nr1n=$(($wl_pksize * $wl_nr1 / $wl_nr + 1))
234 [ "$wl_nr1n" -lt 10 ] && wl_nr1n="0"$wl_nr1n
235 fi
236 if [ "$wl_nr2" -eq 0 ]
237 then
238 wl_nr2n="00"
239 else
240 wl_nr2n=$(($wl_pksize * $wl_nr2 / $wl_nr + 1))
241 [ "$wl_nr2n" -lt 10 ] && wl_nr2n="0"$wl_nr2n
242 fi
243 if [ "$wl_nr5" -eq 0 ]
244 then
245 wl_nr5n="00"
246 else
247 wl_nr5n=$(($wl_pksize * $wl_nr5 / $wl_nr + 1))
248 [ "$wl_nr5n" -lt 10 ] && wl_nr5n="0"$wl_nr5n
249 fi
250 if [ "$wl_nr11" -eq 0 ]
251 then
252 wl_nr11n="00"
253 else
254 wl_nr11n=$(($wl_pksize * $wl_nr11 / $wl_nr + 1))
255 [ "$wl_nr11n" -lt 10 ] && wl_nr11n="0"$wl_nr11n
256 fi
25715simandl echo -n "Tx"${wlc_pkts} $wl_nt1n $wl_nt2n $wl_nt5n $wl_nt11n ${wlc_std}""
258 echo -n "Rx"${wlc_pkts} $wl_nr1n $wl_nr2n $wl_nr5n $wl_nr11n ${wlc_std}""
25913simandl fi
260 
261 [ $wcm_pkts -eq 1 ] && echo -n "Tx" $wl_nt1 $wl_nt2 $wl_nt5 $wl_nt11 "Rx" $wl_nr1 $wl_nr2 $wl_nr5 $wl_nr11 ""
262 
263} # w_pkts
264######################################################################
26517simandlw_managed()
266{ echo $wl_iwctxt | $wl_awkcmd '{print $1,$3,$4,$5" "}'
26718simandl 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
26815simandl 
26918simandl if [ $wcm_macoff -eq 0 ]
27015simandl then
27119simandl wl_mac=`echo -n $wl_iwctxt | $wl_awkcmd '{print $9}'`
27218simandl echo -n "${wlc_mac}$wl_mac${wlc_std} "
27315simandl fi
27418simandl echo $wl_iwctxt | $wl_awkcmd '{print $6,$10" "}'
27515simandl 
27614simandl wl_wtxt=`cat $wl_wireless | grep $wl_iface | $wl_awkcmd '{print $3,$4,$5}' | sed 's/\.//g'`
277 wl_quality=`echo $wl_wtxt | $wl_awkcmd '{print $1}'`
278 wl_signal=`echo $wl_wtxt | $wl_awkcmd '{print $2}'`
2792simandl wl_signal=$(($wl_signal - 256))
28014simandl wl_noise=`echo $wl_wtxt | $wl_awkcmd '{print $3}'`
2812simandl wl_noise=$(($wl_noise - 256))
2825simandl echo "Quality:${wlc_sig}$wl_quality${wlc_std}/92 Signal level:$wl_signal Noise level:$wl_noise "
2832simandl wl_cnt=$wl_quality
284 w_bar
285 echo
286} # w_managed
287 
288######################################################################
289w_master()
29017simandl{ if [ $wcm_oneline -eq 0 ]
29120simandl then
292 echo $wl_iwctxt | $wl_awkcmd '{print $1,$3,$4,$5" "}'
293 if [ $wcm_macoff -eq 1 ]
29415simandl then
29520simandl echo $wl_iwctxt | $wl_awkcmd '{print $6,$11" "}'
296 else
297 echo $wl_iwctxt | $wl_awkcmd '{print $6,$9,$11" "}'
298 fi
299 else
300 echo $wl_iwctxt | $wl_awkcmd '{print $1,$4,$5,$6,$11" "}' | sed 's/ [^": ]*:/ /g'
3015simandl fi
30220simandl wl_numcl=`ls $wl_hostap$wl_iface | grep -c 00`
3032simandl echo $wlm_number_of_clients $wl_numcl
30413simandl 
3055simandl wl_numcllast=$(($wl_numcllast + $wl_numcl))
30613simandl 
30720simandl for wl_mac in `ls $wl_hostap$wl_iface | grep 00 `
3082simandl do
30920simandl wl_macparam=`cat $wl_hostap$wl_iface/$wl_mac | grep -E 'last_rx|last_tx' | sed 's/last_//g'`
310 wl_signal=`echo $wl_macparam | $wl_awkcmd '{print $6}' | sed 's/signal=//g'`
311 wl_silence=`echo $wl_macparam | $wl_awkcmd '{print $4}' | sed 's/silence=//g'`
31211simandl wl_cnt=$(($wl_signal - $wl_silence))
31314simandl wl_ipc=`cat $wl_arp | grep -i $wl_mac | $wl_awkcmd '{print $1}'` # IP adresa peeru z arp tabulky
31413simandl 
31514simandl wl_name=`cat $wl_dhcpcnf | grep -i $wl_mac | $wl_awkcmd '{print $2}'`
316 if [ "$wl_name" = "ethernet" ] || [ "$wl_name" = "" ]
317 then
318 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}'`
319 if [ "$wl_name" = "" ]
320 then
32117simandl wl_name=`cat $wl_dhcplss | grep -i $wl_mac -A 2 | grep -i client-hostname | $wl_awkcmd '{print$2}'`
32214simandl wl_name=`echo $wl_name | $wl_awkcmd '{print$1}' `
323 fi
324 fi
32520simandl if [ $wcm_ppkts -eq 1 ] || [ $wcm_pkts -eq 1 ]
32613simandl then
327 w_pkts
328 fi
329 
3305simandl if [ $wcm_oneline -eq 0 ]
331 then
33215simandl echo -n "${wlc_name}$wl_name${wlc_std} "
3335simandl echo -n "${wlc_ip}$wl_ipc${wlc_std} "
33415simandl if [ $wcm_macoff -eq 0 ]
335 then
336 echo -n "${wlc_mac}$wl_mac${wlc_std} "
337 fi
338 if [ $wcm_threeline -eq 1 ]
339 then
340 echo ""
341 echo -n " "
342 fi
343 echo -n "Signal ${wlc_sig}$wl_cnt${wlc_std} "
344 if [ $wcm_rxtx -eq 0 ]
345 then
346 echo ""
347 else
34820simandl echo $wl_macparam | $wl_awkcmd '{print $1,$2" "}'
34915simandl fi
3505simandl w_bar
351 else
35215simandl if [ $wcm_macoff -eq 0 ]
353 then
354 echo -n "${wlc_mac}$wl_mac${wlc_std} "
355 fi
356 echo -n "${wlc_sig}$wl_cnt${wlc_std} "
35717simandl echo -n "$wl_name "
3585simandl w_bar
359 fi
3604simandl done
36111simandl 
362 echo
3632simandl} # w_master
364 
365######################################################################
366w_iface()
36718simandl{ wl_iwctxt=`$wl_iwccmd $wl_iface 2>/dev/null | grep -v 'Device|Some|Extension' | sed 's/ Nick/_Nick/' | sed 's/Access Point/Access_Point/'`
36814simandl wl_mode=`echo $wl_iwctxt | $wl_awkcmd '{print $5}' | sed 's/Mode://g'`
3692simandl if [ "a$wl_mode" = "aManaged" ]
370 then
371 w_managed
3728simandl elif [ "a$wl_mode" = "aAd-Hoc" ]
373 then
374 w_managed
3752simandl elif [ "a$wl_mode" = "aMaster" ]
376 then
377 w_master
378 else
379 echo $wl_iface $wlm_no_managed_or_master
380 echo
381 fi
382}
383 
384######################################################################
38511simandlw_version()
386{
387 echo wifimon $wl_version
388 exit 0
389}
390######################################################################
3915simandlw_help()
392{
3933simandl echo Pouziti: wifimon [param]
394 echo param:
39511simandl echo -v vypise verzi
3965simandl echo -html generovani html stranky
39713simandl echo -col barevny vypis na obrazovku
3985simandl echo -once vypsani jen jednoho vypisu a pak program skonci
399 echo -oneline vypsani klientu na jednu linku
40015simandl echo -threeline vypsani klienta na trech radcich
401 echo -rxtxoff vypnuti zobrazeni objemu prenesenych dat klienta
40220simandl echo -macoff vypnuti zobrazeni MAC adres
40313simandl echo -ppkts vypsani procentniho pomeru 1M, 2M, 5.5M a 11M paketu pro jednotlive klienty
404 echo -pkts vypsani poctu 1M, 2M, 5.5M a 11M paketu pro jednotlive klienty
40520simandl echo -wlan0 -wlan1 -wlan2 vypise jen uvedene karty a to v danem poctu a poradi
4063simandl echo bez parametru cyklicky vypis na obrazovku
4075simandl exit 0
408}
409######################################################################
410######################################################################
4112simandl 
4125simandlwl_unknown=""
413wl_cnt=1
414wcm_clear=1
415wcm_once=0
41611simandlwcm_col=0
4175simandlwcm_oneline=0
41815simandlwcm_threeline=0
4195simandlwcm_html=0
42015simandlwcm_rxtx=1
42113simandlwcm_ppkts=0
422wcm_pkts=0
4235simandlwcm_ifc=""
42415simandlwcm_macoff=0
4255simandl 
4266simandl# parsing input parameters
4275simandlwhile [ "a$1" != "a" ]
428do
429 case $1 in
43011simandl -v)
431 w_version
432 ;;
4335simandl -help)
434 w_help
435 ;;
436 -once)
437 wcm_once=1
438 shift
439 ;;
440 -oneline)
441 wcm_oneline=1
442 shift
443 ;;
44415simandl -threeline)
445 wcm_threeline=1
446 shift
447 ;;
44811simandl -col)
449 wcm_col=1
4505simandl shift
451 ;;
452 -html)
453 wcm_html=1
454 shift
455 ;;
45615simandl -rxtxoff)
457 wcm_rxtx=0
458 shift
459 ;;
46013simandl -ppkts)
461 wcm_ppkts=1
462 shift
463 ;;
464 -pkts)
465 wcm_pkts=1
466 shift
467 ;;
46815simandl -macoff)
469 wcm_macoff=1
470 shift
471 ;;
4725simandl *)
473 wl_flg=0
47419simandl#wlan check
47520simandl for wl_iface in `ls $wl_hostap`
476 do
477 if [ "a-$wl_iface" = "a$1" ]
4785simandl then
47920simandl wcm_ifc="$wcm_ifc $wl_iface"
480 wl_flg=1
481 fi
482 done
48319simandl# ath check
48420simandl for wl_iface in `ls $wl_sysdev | grep "ath[0..9]"`
485 do
486 if [ "a-$wl_iface" = "a$1" ]
48719simandl then
48820simandl wcm_ifc="$wcm_ifc $wl_iface"
489 wl_flg=1
490 fi
491 done
4925simandl if [ $wl_flg -eq 0 ]
49320simandl then
494 wl_unknown="$wl_unknown$1 "
4955simandl fi
496 shift
497 esac
498done
499 
5006simandl# printing the list of bad parameters (if there are some)
5015simandlif [ "a$wl_unknown" != "a" ]
502then
503 echo "$wlm_unknown $wl_unknown"
504 w_help
505fi
50620simandl 
5076simandl# if no interface is selected then all available are choosen
5085simandlif [ "a$wcm_ifc" = "a" ]
509then
51020simandl wcm_ifc=`ls $wl_hostap ; ls $wl_sysdev | grep "ath[0..9]"`
5115simandlfi
512 
5136simandl# setting for old and last same value to avoid double clear after start
514wl_numcllast=0
515wl_numclold=0
516for wl_iface in $wcm_ifc
517do
51820simandl wl_numcl=`ls $wl_hostap$wl_iface | grep -c 00`
519 wl_numcllast=$(($wl_numcllast + $wl_numcl))
5206simandldone
521wl_numclold=$wl_numcllast
522 
52311simandlif [ $wcm_col -eq 0 ]
5246simandlthen
525 w_bw
52611simandlelse
52715simandl if [ $wcm_html -eq 1 ]
528 then
529 w_colh
530 else
531 w_col
532 fi
5336simandlfi
534 
53513simandlif [ $wcm_html -eq 1 ]
536then
537 [ $wcm_once -eq 1 ] && echo $wl_header || echo $wl_header_refresh
538 for wl_iface in $wcm_ifc
539 do
540 w_iface
541 done
542 echo $wl_footer
543 exit 0
544fi
545 
54615simandl#this is main loop and it will be executed forever
5476simandlwhile [ 1 ]
5485simandl do
54914simandl 
550 # when the number of associated klients has changed we will set for clear screen
5515simandl if [ $wl_numcllast -ne $wl_numclold ]
552 then
553 wl_numclold=$wl_numcllast
554 wcm_clear=1
555 fi
55614simandl 
557 #if it is set for clear screen we will do it except we produce single report
558 if [ $wcm_clear -eq 1 -a $wcm_once -eq 0 ]
5595simandl then
56014simandl echo -n $wl_clrcmde
5615simandl wcm_clear=0
562 fi
563 wl_numcllast=0
56411simandl 
56514simandl #for cyclic report we are trying to set cursor to the top left screen corner
566 if [ $wcm_once -eq 0 ]
567 then
568 echo -n $wl_tptcmde
569 fi
570 
571 #make report for all desired interfaces
57213simandl for wl_iface in $wcm_ifc
573 do
574 w_iface
575 done
576 
57714simandl #when a single report is needed than we are exiting
5785simandl if [ $wcm_once -eq 1 ]
579 then
580 exit 0
581 fi
582 sleep 1
5836simandldone
5845simandl 
585exit 0
586 

Powered by WebSVN 2.2.1