jablonka.czprosek.czf

wifimon

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

 

Line No. Rev Author Line
12simandl#!/bin/bash
23simandl# authors : Petr Simandl www.simandl.cz
311simandl# : Fyzik, Covex
413simandl# release date : 14/8/2003
52simandl# name : wifimon
6# description : hostap powered wifi card monitoring
7# license : GPL
8 
913simandlwl_version="0.4beta8"
1011simandl 
1113simandlPATH=$PATH:$HOME/bin:/bin:/sbin:/usr/bin:/usr/sbin:usr/local/bin:/usr/local/sbin
12 
13wl_iwccmd=`/usr/bin/which iwconfig`
1412simandlif [ "$wl_iwccmd x" = " x" ]
15 then
16 echo "iwconfig not found"
17 exit 1
18fi
197simandlwl_ifccmd="/sbin/ifconfig"
20wl_hnmcmd="/bin/hostname"
212simandlwl_hostap="/proc/net/hostap/"
22wl_wireless="/proc/net/wireless"
233simandlwl_arp="/proc/net/arp"
2411simandlwl_dhcpcnf="/etc/dhcpd.conf"
252simandl 
264simandl 
2713simandlwl_header_refresh="<html><head><meta HTTP-EQUIV=\"Refresh\" CONTENT=\"3\"><title>Wifimon @ `$wl_hnmcmd`</title></head><body BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\"><pre>"
28wl_header="<html><head><title>Wifimon @ `$wl_hnmcmd`</title></head><body BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\"><pre>"
297simandlwl_footer="</pre></body></html>"
30 
31wlm_no_managed_or_master=" neni ani Master ani Managed..."
32wlm_number_of_clients="Pocet asociovanych klientu : "
33wlm_unknown="Nezname parametry nebo neplatne jmeno rozhrani : "
34#wlm_no_managed_or_master=" is not Master or Managed..."
35#wlm_number_of_clients="Number of associated clients : "
36 
3711simandlwlch_signal="="
38wlch_noise="*"
39 
402simandl######################################################################
4111simandlw_col()
4210simandl{
4311simandlwlc_red=`tput setaf 1`
44wlc_green=`tput setaf 2`
45wlc_brown=`tput setaf 3`
46wlc_blue=`tput setaf 4`
47wlc_magenta=`tput setaf 5`
48wlc_lblue=`tput setaf 6`
49wlc_grey=`tput setaf 7`
50wlc_std=`tput sgr0`
51 
52wlc_ip=$wlc_lblue # ip address color
53wlc_mac=$wlc_magenta # mac address color
54wlc_sig=$wlc_red # signal number color
55wlc_bar=$wlc_green # signal bar color
5610simandl}
57######################################################################
584simandlw_bw()
59{
606simandl wlc_ip=""
61 wlc_mac=""
62 wlc_sig=""
63 wlc_bar=""
64 wlc_std=""
654simandl}
66######################################################################
672simandlw_bar()
68{
694simandl echo -n "${wlc_bar}"
7011simandl wl_neg=`expr $wl_cnt \< 0 `
71 if [ "$wl_neg" -eq 1 ]
72 then
73 wl_cnt=$(($wl_cnt * -1 ))
74 wl_bar=$wlch_noise
75 else
76 wl_bar=$wlch_signal
77 fi
782simandl until [ "$wl_cnt" -eq -1 ]
79 do
8011simandl echo -n "$wl_bar"
812simandl wl_cnt=$(($wl_cnt - 1 ))
82 done
83 printf " \n"
846simandl echo -n "${wlc_std}"
8511simandl# tput sgr0
862simandl} # w_bar
87 
88######################################################################
8913simandlw_pkts()
90{
91 wl_macpkts=`cat $wl_hostap$wl_iface/$wl_mac | grep -E 'rx\[|tx\[' | sed 's/=/ /g'`
92 wl_nt1=`echo $wl_macpkts | awk '{print $2}'`
93 wl_nt2=`echo $wl_macpkts | awk '{print $4}'`
94 wl_nt5=`echo $wl_macpkts | awk '{print $6}'`
95 wl_nt11=`echo $wl_macpkts | awk '{print $8}'`
96 wl_nr1=`echo $wl_macpkts | awk '{print $10}'`
97 wl_nr2=`echo $wl_macpkts | awk '{print $12}'`
98 wl_nr5=`echo $wl_macpkts | awk '{print $14}'`
99 wl_nr11=`echo $wl_macpkts | awk '{print $16}'`
100 
101 if [ $wcm_ppkts -eq 1 ]
102 then
103 wl_pksize=$((98))
104 wl_nt=$(($wl_nt1 + $wl_nt2 + wl_nt5 + wl_nt11))
105 if [ "$wl_nt1" -eq 0 ]
106 then
107 wl_nt1n="00"
108 else
109 wl_nt1n=$(($wl_pksize * $wl_nt1 / $wl_nt + 1))
110 [ "$wl_nt1n" -lt 10 ] && wl_nt1n="0"$wl_nt1n
111 fi
112 if [ "$wl_nt2" -eq 0 ]
113 then
114 wl_nt2n="00"
115 else
116 wl_nt2n=$(($wl_pksize * $wl_nt2 / $wl_nt + 1))
117 [ "$wl_nt2n" -lt 10 ] && wl_nt2n="0"$wl_nt2n
118 fi
119 if [ "$wl_nt5" -eq 0 ]
120 then
121 wl_nt5n="00"
122 else
123 wl_nt5n=$(($wl_pksize * $wl_nt5 / $wl_nt + 1))
124 [ "$wl_nt5n" -lt 10 ] && wl_nt5n="0"$wl_nt5n
125 fi
126 if [ "$wl_nt11" -eq 0 ]
127 then
128 wl_nt11n="00"
129 else
130 wl_nt11n=$(($wl_pksize * $wl_nt11 / $wl_nt + 1))
131 [ "$wl_nt11n" -lt 10 ] && wl_nt11n="0"$wl_nt11n
132 fi
133 wl_nr=$((1 + $wl_nr1 + $wl_nr2 + wl_nr5 + wl_nr11))
134 if [ "$wl_nr1" -eq 0 ]
135 then
136 wl_nr1n="00"
137 else
138 wl_nr1n=$(($wl_pksize * $wl_nr1 / $wl_nr + 1))
139 [ "$wl_nr1n" -lt 10 ] && wl_nr1n="0"$wl_nr1n
140 fi
141 if [ "$wl_nr2" -eq 0 ]
142 then
143 wl_nr2n="00"
144 else
145 wl_nr2n=$(($wl_pksize * $wl_nr2 / $wl_nr + 1))
146 [ "$wl_nr2n" -lt 10 ] && wl_nr2n="0"$wl_nr2n
147 fi
148 if [ "$wl_nr5" -eq 0 ]
149 then
150 wl_nr5n="00"
151 else
152 wl_nr5n=$(($wl_pksize * $wl_nr5 / $wl_nr + 1))
153 [ "$wl_nr5n" -lt 10 ] && wl_nr5n="0"$wl_nr5n
154 fi
155 if [ "$wl_nr11" -eq 0 ]
156 then
157 wl_nr11n="00"
158 else
159 wl_nr11n=$(($wl_pksize * $wl_nr11 / $wl_nr + 1))
160 [ "$wl_nr11n" -lt 10 ] && wl_nr11n="0"$wl_nr11n
161 fi
162 echo -n "Tx" $wl_nt1n $wl_nt2n $wl_nt5n $wl_nt11n "Rx" $wl_nr1n $wl_nr2n $wl_nr5n $wl_nr11n ""
163 fi
164 
165 [ $wcm_pkts -eq 1 ] && echo -n "Tx" $wl_nt1 $wl_nt2 $wl_nt5 $wl_nt11 "Rx" $wl_nr1 $wl_nr2 $wl_nr5 $wl_nr11 ""
166 
167} # w_pkts
168######################################################################
1692simandlw_managed()
1707simandl{ echo $wl_iwctxt | awk '{print $1,$3,$4,$5" "}'
171 echo -n `$wl_ifccmd $wl_iface | grep -E "inet addr|inet adr" | awk '{print $2" "}' | sed s/ad*r://g`" " # IP adresa mastera z ifconfig
172 echo $wl_iwctxt | awk '{print $9,$6,$11" "}'
173 wl_wtxt=`cat $wl_wireless | grep $wl_iface | awk '{print $3,$4,$5}' | sed 's/\.//g'`
174 wl_quality=`echo $wl_wtxt | awk '{print $1}'`
175 wl_signal=`echo $wl_wtxt | awk '{print $2}'`
1762simandl wl_signal=$(($wl_signal - 256))
1777simandl wl_noise=`echo $wl_wtxt | awk '{print $3}'`
1782simandl wl_noise=$(($wl_noise - 256))
1795simandl echo "Quality:${wlc_sig}$wl_quality${wlc_std}/92 Signal level:$wl_signal Noise level:$wl_noise "
1802simandl wl_cnt=$wl_quality
181 w_bar
182 echo
183} # w_managed
184 
185######################################################################
186w_master()
1875simandl{ if [ $wcm_oneline -eq 0 ]
188 then
1897simandl echo $wl_iwctxt | awk '{print $1,$3,$4,$5" "}'
190 echo $wl_iwctxt | awk '{print $6,$9,$11" "}'
1915simandl else
1927simandl echo $wl_iwctxt | awk '{print $1,$4,$5,$6,$11" "}' | sed 's/ [^": ]*:/ /g'
1935simandl fi
19411simandl 
1952simandl wl_numcl=`ls $wl_hostap$wl_iface | grep -c 00`
196 echo $wlm_number_of_clients $wl_numcl
19713simandl 
1985simandl wl_numcllast=$(($wl_numcllast + $wl_numcl))
19913simandl 
2003simandl for wl_mac in `ls $wl_hostap$wl_iface | grep 00 `
2012simandl do
20211simandl wl_macparam=`cat $wl_hostap$wl_iface/$wl_mac | grep -E 'last_rx|last_tx' | sed 's/last_//g'`
203 wl_signal=`echo $wl_macparam | awk '{print $5}' | sed 's/signal=//g'`
204 wl_silence=`echo $wl_macparam | awk '{print $4}' | sed 's/silence=//g'`
205 wl_cnt=$(($wl_signal - $wl_silence))
2068simandl wl_ipc=`cat $wl_arp | grep -i $wl_mac | awk '{print $1}'` # IP adresa peeru z arp tabulky
20711simandl wl_name=`cat $wl_dhcpcnf | grep -i $wl_mac | awk '{print $2}'`
20813simandl 
209 if [ $wcm_ppkts -eq 1 ] || [ $wcm_pkts -eq 1 ]
210 then
211 w_pkts
212 fi
213 
2145simandl if [ $wcm_oneline -eq 0 ]
215 then
21611simandl echo -n "$wl_name "
2175simandl echo -n "${wlc_ip}$wl_ipc${wlc_std} "
21811simandl echo -n "${wlc_mac}$wl_mac${wlc_std} Signal ${wlc_sig}$wl_cnt${wlc_std} "
219 echo $wl_macparam | awk '{print $1,$2" "}'
2205simandl w_bar
221 else
22211simandl echo -n "$wl_name "
223 echo -n "${wlc_mac}$wl_mac${wlc_std} ${wlc_sig}$wl_cnt${wlc_std} "
2245simandl w_bar
225 fi
2264simandl done
22711simandl 
228 echo
2292simandl} # w_master
230 
231######################################################################
232w_iface()
23313simandl{ wl_iwctxt=`$wl_iwccmd $wl_iface 2>/dev/null | grep -v 'Device|Some|Extension' | sed 's/ Nick/_Nick/'`
2347simandl wl_mode=`echo $wl_iwctxt | awk '{print $5}' | sed 's/Mode://g'`
2352simandl if [ "a$wl_mode" = "aManaged" ]
236 then
237 w_managed
2388simandl elif [ "a$wl_mode" = "aAd-Hoc" ]
239 then
240 w_managed
2412simandl elif [ "a$wl_mode" = "aMaster" ]
242 then
243 w_master
244 else
245 echo $wl_iface $wlm_no_managed_or_master
246 echo
247 fi
248}
249 
250######################################################################
25111simandlw_version()
252{
253 echo wifimon $wl_version
254 exit 0
255}
256######################################################################
2575simandlw_help()
258{
2593simandl echo Pouziti: wifimon [param]
260 echo param:
26111simandl echo -v vypise verzi
2625simandl echo -html generovani html stranky
26313simandl echo -col barevny vypis na obrazovku
2645simandl echo -once vypsani jen jednoho vypisu a pak program skonci
265 echo -oneline vypsani klientu na jednu linku
26613simandl echo -ppkts vypsani procentniho pomeru 1M, 2M, 5.5M a 11M paketu pro jednotlive klienty
267 echo -pkts vypsani poctu 1M, 2M, 5.5M a 11M paketu pro jednotlive klienty
2685simandl echo -wlan0 -wlan1 -wlan2 vypise jen uvedene karty a to v danem poctu a poradi
2693simandl echo bez parametru cyklicky vypis na obrazovku
2705simandl exit 0
271}
272######################################################################
273######################################################################
2742simandl 
2755simandlwl_unknown=""
276wl_cnt=1
277wcm_clear=1
278wcm_once=0
27911simandlwcm_col=0
2805simandlwcm_oneline=0
281wcm_html=0
28213simandlwcm_ppkts=0
283wcm_pkts=0
2845simandlwcm_ifc=""
285 
2866simandl# parsing input parameters
2875simandlwhile [ "a$1" != "a" ]
288do
289 case $1 in
29011simandl -v)
291 w_version
292 ;;
2935simandl -help)
294 w_help
295 ;;
296 -once)
297 wcm_once=1
298 shift
299 ;;
300 -oneline)
301 wcm_oneline=1
302 shift
303 ;;
30411simandl -col)
305 wcm_col=1
3065simandl shift
307 ;;
308 -html)
309 wcm_html=1
310 shift
311 ;;
31213simandl -ppkts)
313 wcm_ppkts=1
314 shift
315 ;;
316 -pkts)
317 wcm_pkts=1
318 shift
319 ;;
3205simandl *)
321 wl_flg=0
322 for wl_iface in `ls $wl_hostap`
323 do
324 if [ "a-$wl_iface" = "a$1" ]
325 then
326 wcm_ifc="$wcm_ifc $wl_iface"
327 wl_flg=1
328 fi
329 done
330 if [ $wl_flg -eq 0 ]
331 then
332 wl_unknown="$wl_unknown$1 "
333 fi
334 shift
335 esac
336done
337 
3386simandl# printing the list of bad parameters (if there are some)
3395simandlif [ "a$wl_unknown" != "a" ]
340then
341 echo "$wlm_unknown $wl_unknown"
342 w_help
343fi
344 
3456simandl# if no interface is selected then all available are choosen
3465simandlif [ "a$wcm_ifc" = "a" ]
347then
348 wcm_ifc=`ls $wl_hostap`
349fi
350 
3516simandl# setting for old and last same value to avoid double clear after start
352wl_numcllast=0
353wl_numclold=0
354for wl_iface in $wcm_ifc
355do
356 wl_numcl=`ls $wl_hostap$wl_iface | grep -c 00`
357 wl_numcllast=$(($wl_numcllast + $wl_numcl))
358done
359wl_numclold=$wl_numcllast
360 
36111simandlif [ $wcm_col -eq 0 ]
3626simandlthen
363 w_bw
36411simandlelse
365 w_col
3666simandlfi
367 
36813simandlif [ $wcm_html -eq 1 ]
369then
370 w_bw
371 [ $wcm_once -eq 1 ] && echo $wl_header || echo $wl_header_refresh
372 for wl_iface in $wcm_ifc
373 do
374 w_iface
375 done
376 echo $wl_footer
377 exit 0
378fi
379 
3806simandlwhile [ 1 ]
3815simandl do
382 if [ $wl_numcllast -ne $wl_numclold ]
383 then
384 wl_numclold=$wl_numcllast
385 wcm_clear=1
386 fi
38711simandl if [ $wcm_clear -eq 1 -a $wcm_html -ne 1 ]
3885simandl then
3897simandl clear
3905simandl wcm_clear=0
391 fi
392 wl_numcllast=0
39311simandl 
39413simandl [ -e /usr/bin/tput ] && tput cup 0 0 || clear
395 for wl_iface in $wcm_ifc
396 do
397 w_iface
398 done
399 
4005simandl if [ $wcm_once -eq 1 ]
401 then
402 exit 0
403 fi
404 sleep 1
4056simandldone
4065simandl 
407exit 0
408 

Powered by WebSVN 2.2.1