jablonka.czprosek.czf

wifimon

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

 

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 
914simandlwl_version="0.5.0"
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"
26 
27#testing all settings
28 
2912simandlif [ "$wl_iwccmd x" = " x" ]
30 then
31 echo "iwconfig not found"
32 exit 1
33fi
342simandl 
3514simandlif [ "$wl_ifccmd x" = " x" ]
36 then
37 echo "ifconfig not found"
38 exit 1
39fi
404simandl 
4114simandlif [ "$wl_hnmcmd x" = " x" ]
42 then
43 echo "hostname not found"
44 exit 1
45fi
46 
47if [ "$wl_awkcmd x" = " x" ]
48 then
49 echo "awk not found"
50 exit 1
51fi
52 
53if [ -d $wl_hostap ]
54 then
55 wl_nop=1
56 else
57 echo "hostap not found"
58 exit 1
59fi
60 
61if [ -e $wl_wireless ]
62 then
63 wl_nop=1
64 else
65 echo "$wl_wireless not found"
66 exit 1
67fi
68 
69if [ -e $wl_arp ]
70 then
71 wl_nop=1
72 else
73 echo "$wl_arp not found"
74 exit 1
75fi
76 
77if [ -e $wl_dhcpcnf ]
78 then
79 wl_nop=1
80 else
81 echo "$wl_dhcpcnf not found"
82 wl_dhcpcnf="/dev/null"
83fi
84 
85if [ -e $wl_dhcplss ]
86 then
87 wl_nop=1
88 else
89 echo "$wl_dhcplss not found"
90 wl_dhcplss="/dev/null"
91fi
92 
9313simandlwl_header_refresh="<html><head><meta HTTP-EQUIV=\"Refresh\" CONTENT=\"3\"><title>Wifimon @ `$wl_hnmcmd`</title></head><body BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\"><pre>"
94wl_header="<html><head><title>Wifimon @ `$wl_hnmcmd`</title></head><body BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\"><pre>"
957simandlwl_footer="</pre></body></html>"
96 
97wlm_no_managed_or_master=" neni ani Master ani Managed..."
98wlm_number_of_clients="Pocet asociovanych klientu : "
99wlm_unknown="Nezname parametry nebo neplatne jmeno rozhrani : "
100#wlm_no_managed_or_master=" is not Master or Managed..."
101#wlm_number_of_clients="Number of associated clients : "
102 
10311simandlwlch_signal="="
104wlch_noise="*"
105 
1062simandl######################################################################
10711simandlw_col()
10810simandl{
10911simandlwlc_red=`tput setaf 1`
110wlc_green=`tput setaf 2`
111wlc_brown=`tput setaf 3`
112wlc_blue=`tput setaf 4`
113wlc_magenta=`tput setaf 5`
114wlc_lblue=`tput setaf 6`
115wlc_grey=`tput setaf 7`
116wlc_std=`tput sgr0`
117 
118wlc_ip=$wlc_lblue # ip address color
119wlc_mac=$wlc_magenta # mac address color
120wlc_sig=$wlc_red # signal number color
121wlc_bar=$wlc_green # signal bar color
12210simandl}
123######################################################################
1244simandlw_bw()
125{
1266simandl wlc_ip=""
127 wlc_mac=""
128 wlc_sig=""
129 wlc_bar=""
130 wlc_std=""
1314simandl}
132######################################################################
1332simandlw_bar()
134{
1354simandl echo -n "${wlc_bar}"
13611simandl wl_neg=`expr $wl_cnt \< 0 `
137 if [ "$wl_neg" -eq 1 ]
138 then
139 wl_cnt=$(($wl_cnt * -1 ))
140 wl_bar=$wlch_noise
141 else
142 wl_bar=$wlch_signal
143 fi
1442simandl until [ "$wl_cnt" -eq -1 ]
145 do
14611simandl echo -n "$wl_bar"
1472simandl wl_cnt=$(($wl_cnt - 1 ))
148 done
149 printf " \n"
1506simandl echo -n "${wlc_std}"
15111simandl# tput sgr0
1522simandl} # w_bar
153 
154######################################################################
15513simandlw_pkts()
156{
157 wl_macpkts=`cat $wl_hostap$wl_iface/$wl_mac | grep -E 'rx\[|tx\[' | sed 's/=/ /g'`
15814simandl wl_nt1=`echo $wl_macpkts | $wl_awkcmd '{print $2}'`
159 wl_nt2=`echo $wl_macpkts | $wl_awkcmd '{print $4}'`
160 wl_nt5=`echo $wl_macpkts | $wl_awkcmd '{print $6}'`
161 wl_nt11=`echo $wl_macpkts | $wl_awkcmd '{print $8}'`
162 wl_nr1=`echo $wl_macpkts | $wl_awkcmd '{print $10}'`
163 wl_nr2=`echo $wl_macpkts | $wl_awkcmd '{print $12}'`
164 wl_nr5=`echo $wl_macpkts | $wl_awkcmd '{print $14}'`
165 wl_nr11=`echo $wl_macpkts | $wl_awkcmd '{print $16}'`
16613simandl 
167 if [ $wcm_ppkts -eq 1 ]
168 then
169 wl_pksize=$((98))
170 wl_nt=$(($wl_nt1 + $wl_nt2 + wl_nt5 + wl_nt11))
171 if [ "$wl_nt1" -eq 0 ]
172 then
173 wl_nt1n="00"
174 else
175 wl_nt1n=$(($wl_pksize * $wl_nt1 / $wl_nt + 1))
176 [ "$wl_nt1n" -lt 10 ] && wl_nt1n="0"$wl_nt1n
177 fi
178 if [ "$wl_nt2" -eq 0 ]
179 then
180 wl_nt2n="00"
181 else
182 wl_nt2n=$(($wl_pksize * $wl_nt2 / $wl_nt + 1))
183 [ "$wl_nt2n" -lt 10 ] && wl_nt2n="0"$wl_nt2n
184 fi
185 if [ "$wl_nt5" -eq 0 ]
186 then
187 wl_nt5n="00"
188 else
189 wl_nt5n=$(($wl_pksize * $wl_nt5 / $wl_nt + 1))
190 [ "$wl_nt5n" -lt 10 ] && wl_nt5n="0"$wl_nt5n
191 fi
192 if [ "$wl_nt11" -eq 0 ]
193 then
194 wl_nt11n="00"
195 else
196 wl_nt11n=$(($wl_pksize * $wl_nt11 / $wl_nt + 1))
197 [ "$wl_nt11n" -lt 10 ] && wl_nt11n="0"$wl_nt11n
198 fi
199 wl_nr=$((1 + $wl_nr1 + $wl_nr2 + wl_nr5 + wl_nr11))
200 if [ "$wl_nr1" -eq 0 ]
201 then
202 wl_nr1n="00"
203 else
204 wl_nr1n=$(($wl_pksize * $wl_nr1 / $wl_nr + 1))
205 [ "$wl_nr1n" -lt 10 ] && wl_nr1n="0"$wl_nr1n
206 fi
207 if [ "$wl_nr2" -eq 0 ]
208 then
209 wl_nr2n="00"
210 else
211 wl_nr2n=$(($wl_pksize * $wl_nr2 / $wl_nr + 1))
212 [ "$wl_nr2n" -lt 10 ] && wl_nr2n="0"$wl_nr2n
213 fi
214 if [ "$wl_nr5" -eq 0 ]
215 then
216 wl_nr5n="00"
217 else
218 wl_nr5n=$(($wl_pksize * $wl_nr5 / $wl_nr + 1))
219 [ "$wl_nr5n" -lt 10 ] && wl_nr5n="0"$wl_nr5n
220 fi
221 if [ "$wl_nr11" -eq 0 ]
222 then
223 wl_nr11n="00"
224 else
225 wl_nr11n=$(($wl_pksize * $wl_nr11 / $wl_nr + 1))
226 [ "$wl_nr11n" -lt 10 ] && wl_nr11n="0"$wl_nr11n
227 fi
228 echo -n "Tx" $wl_nt1n $wl_nt2n $wl_nt5n $wl_nt11n "Rx" $wl_nr1n $wl_nr2n $wl_nr5n $wl_nr11n ""
229 fi
230 
231 [ $wcm_pkts -eq 1 ] && echo -n "Tx" $wl_nt1 $wl_nt2 $wl_nt5 $wl_nt11 "Rx" $wl_nr1 $wl_nr2 $wl_nr5 $wl_nr11 ""
232 
233} # w_pkts
234######################################################################
2352simandlw_managed()
23614simandl{ echo $wl_iwctxt | $wl_awkcmd '{print $1,$3,$4,$5" "}'
237 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
238 echo $wl_iwctxt | $wl_awkcmd '{print $9,$6,$11" "}'
239 wl_wtxt=`cat $wl_wireless | grep $wl_iface | $wl_awkcmd '{print $3,$4,$5}' | sed 's/\.//g'`
240 wl_quality=`echo $wl_wtxt | $wl_awkcmd '{print $1}'`
241 wl_signal=`echo $wl_wtxt | $wl_awkcmd '{print $2}'`
2422simandl wl_signal=$(($wl_signal - 256))
24314simandl wl_noise=`echo $wl_wtxt | $wl_awkcmd '{print $3}'`
2442simandl wl_noise=$(($wl_noise - 256))
2455simandl echo "Quality:${wlc_sig}$wl_quality${wlc_std}/92 Signal level:$wl_signal Noise level:$wl_noise "
2462simandl wl_cnt=$wl_quality
247 w_bar
248 echo
249} # w_managed
250 
251######################################################################
252w_master()
2535simandl{ if [ $wcm_oneline -eq 0 ]
254 then
25514simandl echo $wl_iwctxt | $wl_awkcmd '{print $1,$3,$4,$5" "}'
256 echo $wl_iwctxt | $wl_awkcmd '{print $6,$9,$11" "}'
2575simandl else
25814simandl echo $wl_iwctxt | $wl_awkcmd '{print $1,$4,$5,$6,$11" "}' | sed 's/ [^": ]*:/ /g'
2595simandl fi
26011simandl 
2612simandl wl_numcl=`ls $wl_hostap$wl_iface | grep -c 00`
262 echo $wlm_number_of_clients $wl_numcl
26313simandl 
2645simandl wl_numcllast=$(($wl_numcllast + $wl_numcl))
26513simandl 
2663simandl for wl_mac in `ls $wl_hostap$wl_iface | grep 00 `
2672simandl do
26811simandl wl_macparam=`cat $wl_hostap$wl_iface/$wl_mac | grep -E 'last_rx|last_tx' | sed 's/last_//g'`
26914simandl wl_signal=`echo $wl_macparam | $wl_awkcmd '{print $5}' | sed 's/signal=//g'`
270 wl_silence=`echo $wl_macparam | $wl_awkcmd '{print $4}' | sed 's/silence=//g'`
27111simandl wl_cnt=$(($wl_signal - $wl_silence))
27214simandl wl_ipc=`cat $wl_arp | grep -i $wl_mac | $wl_awkcmd '{print $1}'` # IP adresa peeru z arp tabulky
27313simandl 
27414simandl wl_name=`cat $wl_dhcpcnf | grep -i $wl_mac | $wl_awkcmd '{print $2}'`
275 if [ "$wl_name" = "ethernet" ] || [ "$wl_name" = "" ]
276 then
277 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}'`
278 if [ "$wl_name" = "" ]
279 then
280 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}'`
281 wl_name=`echo $wl_name | $wl_awkcmd '{print$1}' `
282 fi
283 fi
28413simandl if [ $wcm_ppkts -eq 1 ] || [ $wcm_pkts -eq 1 ]
285 then
286 w_pkts
287 fi
288 
2895simandl if [ $wcm_oneline -eq 0 ]
290 then
29111simandl echo -n "$wl_name "
2925simandl echo -n "${wlc_ip}$wl_ipc${wlc_std} "
29311simandl echo -n "${wlc_mac}$wl_mac${wlc_std} Signal ${wlc_sig}$wl_cnt${wlc_std} "
29414simandl echo $wl_macparam | $wl_awkcmd '{print $1,$2" "}'
2955simandl w_bar
296 else
29711simandl echo -n "$wl_name "
298 echo -n "${wlc_mac}$wl_mac${wlc_std} ${wlc_sig}$wl_cnt${wlc_std} "
2995simandl w_bar
300 fi
3014simandl done
30211simandl 
303 echo
3042simandl} # w_master
305 
306######################################################################
307w_iface()
30813simandl{ wl_iwctxt=`$wl_iwccmd $wl_iface 2>/dev/null | grep -v 'Device|Some|Extension' | sed 's/ Nick/_Nick/'`
30914simandl wl_mode=`echo $wl_iwctxt | $wl_awkcmd '{print $5}' | sed 's/Mode://g'`
3102simandl if [ "a$wl_mode" = "aManaged" ]
311 then
312 w_managed
3138simandl elif [ "a$wl_mode" = "aAd-Hoc" ]
314 then
315 w_managed
3162simandl elif [ "a$wl_mode" = "aMaster" ]
317 then
318 w_master
319 else
320 echo $wl_iface $wlm_no_managed_or_master
321 echo
322 fi
323}
324 
325######################################################################
32611simandlw_version()
327{
328 echo wifimon $wl_version
329 exit 0
330}
331######################################################################
3325simandlw_help()
333{
3343simandl echo Pouziti: wifimon [param]
335 echo param:
33611simandl echo -v vypise verzi
3375simandl echo -html generovani html stranky
33813simandl echo -col barevny vypis na obrazovku
3395simandl echo -once vypsani jen jednoho vypisu a pak program skonci
340 echo -oneline vypsani klientu na jednu linku
34113simandl echo -ppkts vypsani procentniho pomeru 1M, 2M, 5.5M a 11M paketu pro jednotlive klienty
342 echo -pkts vypsani poctu 1M, 2M, 5.5M a 11M paketu pro jednotlive klienty
3435simandl echo -wlan0 -wlan1 -wlan2 vypise jen uvedene karty a to v danem poctu a poradi
3443simandl echo bez parametru cyklicky vypis na obrazovku
3455simandl exit 0
346}
347######################################################################
348######################################################################
3492simandl 
3505simandlwl_unknown=""
351wl_cnt=1
352wcm_clear=1
353wcm_once=0
35411simandlwcm_col=0
3555simandlwcm_oneline=0
356wcm_html=0
35713simandlwcm_ppkts=0
358wcm_pkts=0
3595simandlwcm_ifc=""
360 
3616simandl# parsing input parameters
3625simandlwhile [ "a$1" != "a" ]
363do
364 case $1 in
36511simandl -v)
366 w_version
367 ;;
3685simandl -help)
369 w_help
370 ;;
371 -once)
372 wcm_once=1
373 shift
374 ;;
375 -oneline)
376 wcm_oneline=1
377 shift
378 ;;
37911simandl -col)
380 wcm_col=1
3815simandl shift
382 ;;
383 -html)
384 wcm_html=1
385 shift
386 ;;
38713simandl -ppkts)
388 wcm_ppkts=1
389 shift
390 ;;
391 -pkts)
392 wcm_pkts=1
393 shift
394 ;;
3955simandl *)
396 wl_flg=0
397 for wl_iface in `ls $wl_hostap`
398 do
399 if [ "a-$wl_iface" = "a$1" ]
400 then
401 wcm_ifc="$wcm_ifc $wl_iface"
402 wl_flg=1
403 fi
404 done
405 if [ $wl_flg -eq 0 ]
406 then
407 wl_unknown="$wl_unknown$1 "
408 fi
409 shift
410 esac
411done
412 
4136simandl# printing the list of bad parameters (if there are some)
4145simandlif [ "a$wl_unknown" != "a" ]
415then
416 echo "$wlm_unknown $wl_unknown"
417 w_help
418fi
419 
4206simandl# if no interface is selected then all available are choosen
4215simandlif [ "a$wcm_ifc" = "a" ]
422then
423 wcm_ifc=`ls $wl_hostap`
424fi
425 
4266simandl# setting for old and last same value to avoid double clear after start
427wl_numcllast=0
428wl_numclold=0
429for wl_iface in $wcm_ifc
430do
431 wl_numcl=`ls $wl_hostap$wl_iface | grep -c 00`
432 wl_numcllast=$(($wl_numcllast + $wl_numcl))
433done
434wl_numclold=$wl_numcllast
435 
43611simandlif [ $wcm_col -eq 0 ]
4376simandlthen
438 w_bw
43911simandlelse
440 w_col
4416simandlfi
442 
44313simandlif [ $wcm_html -eq 1 ]
444then
445 w_bw
446 [ $wcm_once -eq 1 ] && echo $wl_header || echo $wl_header_refresh
447 for wl_iface in $wcm_ifc
448 do
449 w_iface
450 done
451 echo $wl_footer
452 exit 0
453fi
454 
45514simandl#this is main loop and it will be executer forever
4566simandlwhile [ 1 ]
4575simandl do
45814simandl 
459 # when the number of associated klients has changed we will set for clear screen
4605simandl if [ $wl_numcllast -ne $wl_numclold ]
461 then
462 wl_numclold=$wl_numcllast
463 wcm_clear=1
464 fi
46514simandl 
466 #if it is set for clear screen we will do it except we produce single report
467 if [ $wcm_clear -eq 1 -a $wcm_once -eq 0 ]
4685simandl then
46914simandl echo -n $wl_clrcmde
4705simandl wcm_clear=0
471 fi
472 wl_numcllast=0
47311simandl 
47414simandl #for cyclic report we are trying to set cursor to the top left screen corner
475 if [ $wcm_once -eq 0 ]
476 then
477 echo -n $wl_tptcmde
478 fi
479 
480 #make report for all desired interfaces
48113simandl for wl_iface in $wcm_ifc
482 do
483 w_iface
484 done
485 
48614simandl #when a single report is needed than we are exiting
4875simandl if [ $wcm_once -eq 1 ]
488 then
489 exit 0
490 fi
491 sleep 1
4926simandldone
4935simandl 
494exit 0
495 

Powered by WebSVN 2.2.1