1 | 2 | simandl | #!/bin/bash |
2 | 3 | simandl | # authors : Petr Simandl www.simandl.cz |
3 | 14 | simandl | # : Fyzik, Covex, Tydyt |
4 | | | # release date : 05/10/2003 |
5 | 2 | simandl | # name : wifimon |
6 | | | # description : hostap powered wifi card monitoring |
7 | | | # license : GPL |
8 | | | |
9 | 15 | simandl | wl_version="0.5.2" |
10 | 11 | simandl | |
11 | 13 | simandl | PATH=$PATH:$HOME/bin:/bin:/sbin:/usr/bin:/usr/sbin:usr/local/bin:/usr/local/sbin |
12 | | | |
13 | 14 | simandl | wl_iwccmd=`which iwconfig` |
14 | | | wl_ifccmd=`which ifconfig` |
15 | | | wl_hnmcmd=`which hostname` |
16 | | | wl_awkcmd=`which awk` |
17 | | | |
18 | | | wl_tptcmde="[1;1H" |
19 | | | wl_clrcmde="[H[2J" |
20 | | | |
21 | | | wl_hostap="/proc/net/hostap/" |
22 | | | wl_wireless="/proc/net/wireless" |
23 | | | wl_arp="/proc/net/arp" |
24 | | | wl_dhcpcnf="/etc/dhcpd.conf" |
25 | | | wl_dhcplss="/var/lib/dhcp/dhcpd.leases" |
26 | 16 | simandl | #wl_dhcpcnf="/etc/dhcp3/dhcpd.conf" |
27 | | | #wl_dhcplss="/var/lib/dhcp3/dhcpd.leases" |
28 | 14 | simandl | |
29 | | | #testing all settings |
30 | | | |
31 | 12 | simandl | if [ "$wl_iwccmd x" = " x" ] |
32 | | | then |
33 | | | echo "iwconfig not found" |
34 | | | exit 1 |
35 | | | fi |
36 | 2 | simandl | |
37 | 14 | simandl | if [ "$wl_ifccmd x" = " x" ] |
38 | | | then |
39 | | | echo "ifconfig not found" |
40 | | | exit 1 |
41 | | | fi |
42 | 4 | simandl | |
43 | 14 | simandl | if [ "$wl_hnmcmd x" = " x" ] |
44 | | | then |
45 | | | echo "hostname not found" |
46 | | | exit 1 |
47 | | | fi |
48 | | | |
49 | | | if [ "$wl_awkcmd x" = " x" ] |
50 | | | then |
51 | | | echo "awk not found" |
52 | | | exit 1 |
53 | | | fi |
54 | | | |
55 | | | if [ -d $wl_hostap ] |
56 | | | then |
57 | | | wl_nop=1 |
58 | | | else |
59 | | | echo "hostap not found" |
60 | | | exit 1 |
61 | | | fi |
62 | | | |
63 | | | if [ -e $wl_wireless ] |
64 | | | then |
65 | | | wl_nop=1 |
66 | | | else |
67 | | | echo "$wl_wireless not found" |
68 | | | exit 1 |
69 | | | fi |
70 | | | |
71 | | | if [ -e $wl_arp ] |
72 | | | then |
73 | | | wl_nop=1 |
74 | | | else |
75 | | | echo "$wl_arp not found" |
76 | | | exit 1 |
77 | | | fi |
78 | | | |
79 | | | if [ -e $wl_dhcpcnf ] |
80 | | | then |
81 | | | wl_nop=1 |
82 | | | else |
83 | | | echo "$wl_dhcpcnf not found" |
84 | | | wl_dhcpcnf="/dev/null" |
85 | | | fi |
86 | | | |
87 | | | if [ -e $wl_dhcplss ] |
88 | | | then |
89 | | | wl_nop=1 |
90 | | | else |
91 | | | echo "$wl_dhcplss not found" |
92 | | | wl_dhcplss="/dev/null" |
93 | | | fi |
94 | | | |
95 | 15 | simandl | wl_header_refresh="<html><head><meta HTTP-EQUIV=\"Refresh\" CONTENT=\"15\"><title>Wifimon @ `$wl_hnmcmd`</title></head><body BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\"><pre>" |
96 | 13 | simandl | wl_header="<html><head><title>Wifimon @ `$wl_hnmcmd`</title></head><body BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\"><pre>" |
97 | 7 | simandl | wl_footer="</pre></body></html>" |
98 | | | |
99 | | | wlm_no_managed_or_master=" neni ani Master ani Managed..." |
100 | | | wlm_number_of_clients="Pocet asociovanych klientu : " |
101 | | | wlm_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 | | | |
105 | 11 | simandl | wlch_signal="=" |
106 | | | wlch_noise="*" |
107 | | | |
108 | 2 | simandl | ###################################################################### |
109 | 11 | simandl | w_col() |
110 | 10 | simandl | { |
111 | 15 | simandl | wlc_red=`tput setaf 1` # ruda (Red) |
112 | | | wlc_green=`tput setaf 2` # zelena (Lime) |
113 | | | wlc_brown=`tput setaf 3` # zluta (Yellow) |
114 | | | wlc_blue=`tput setaf 4` # modra (Blue) |
115 | | | wlc_magenta=`tput setaf 5` # fialova (Fuchsia) |
116 | | | wlc_lblue=`tput setaf 6` # svetle modra (Aqua) |
117 | | | wlc_grey=`tput setaf 7` # bila (White) |
118 | 11 | simandl | wlc_std=`tput sgr0` |
119 | | | |
120 | 15 | simandl | wlc_pkts=$wlc_red # Rx,Tx info color |
121 | 11 | simandl | wlc_ip=$wlc_lblue # ip address color |
122 | | | wlc_mac=$wlc_magenta # mac address color |
123 | 15 | simandl | wlc_name=$wlc_magenta # host name color |
124 | 11 | simandl | wlc_sig=$wlc_red # signal number color |
125 | | | wlc_bar=$wlc_green # signal bar color |
126 | 15 | simandl | wlc_noise=$wlc_red # Signal noise color |
127 | 10 | simandl | } |
128 | | | ###################################################################### |
129 | 15 | simandl | w_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 | | | ###################################################################### |
149 | 4 | simandl | w_bw() |
150 | | | { |
151 | 15 | simandl | wlc_pkts="" |
152 | 6 | simandl | wlc_ip="" |
153 | | | wlc_mac="" |
154 | | | wlc_sig="" |
155 | | | wlc_bar="" |
156 | 15 | simandl | wlc_noise="" |
157 | 6 | simandl | wlc_std="" |
158 | 4 | simandl | } |
159 | | | ###################################################################### |
160 | 2 | simandl | w_bar() |
161 | | | { |
162 | 11 | simandl | wl_neg=`expr $wl_cnt \< 0 ` |
163 | | | if [ "$wl_neg" -eq 1 ] |
164 | | | then |
165 | 15 | simandl | echo -n "${wlc_noise}" |
166 | 11 | simandl | wl_cnt=$(($wl_cnt * -1 )) |
167 | | | wl_bar=$wlch_noise |
168 | | | else |
169 | 15 | simandl | echo -n "${wlc_bar}" |
170 | 11 | simandl | wl_bar=$wlch_signal |
171 | | | fi |
172 | 2 | simandl | until [ "$wl_cnt" -eq -1 ] |
173 | | | do |
174 | 11 | simandl | echo -n "$wl_bar" |
175 | 2 | simandl | wl_cnt=$(($wl_cnt - 1 )) |
176 | | | done |
177 | | | printf " \n" |
178 | 6 | simandl | echo -n "${wlc_std}" |
179 | 11 | simandl | # tput sgr0 |
180 | 2 | simandl | } # w_bar |
181 | | | |
182 | | | ###################################################################### |
183 | 13 | simandl | w_pkts() |
184 | | | { |
185 | | | wl_macpkts=`cat $wl_hostap$wl_iface/$wl_mac | grep -E 'rx\[|tx\[' | sed 's/=/ /g'` |
186 | 14 | simandl | 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}'` |
194 | 13 | simandl | |
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 |
256 | 15 | simandl | 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}"" |
258 | 13 | simandl | 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 | | | ###################################################################### |
264 | 16 | simandl | w_managed() { |
265 | | | echo $wl_iwctxt | $wl_awkcmd '{print $1,$3,$4,$5" "}' |
266 | 14 | simandl | 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 |
267 | 15 | simandl | |
268 | | | if [ $wcm_macoff -eq 1 ] |
269 | | | then |
270 | 16 | simandl | echo $wl_iwctxt | $wl_awkcmd '{print $6""$7,$12""$13" "}' |
271 | 15 | simandl | else |
272 | 16 | simandl | echo $wl_iwctxt | $wl_awkcmd '{print $10,$6""$7,$12""$13" "}' |
273 | 15 | simandl | fi |
274 | | | |
275 | 14 | simandl | 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}'` |
278 | 2 | simandl | wl_signal=$(($wl_signal - 256)) |
279 | 14 | simandl | wl_noise=`echo $wl_wtxt | $wl_awkcmd '{print $3}'` |
280 | 2 | simandl | wl_noise=$(($wl_noise - 256)) |
281 | 5 | simandl | echo "Quality:${wlc_sig}$wl_quality${wlc_std}/92 Signal level:$wl_signal Noise level:$wl_noise " |
282 | 2 | simandl | wl_cnt=$wl_quality |
283 | | | w_bar |
284 | | | echo |
285 | | | } # w_managed |
286 | | | |
287 | | | ###################################################################### |
288 | | | w_master() |
289 | 16 | simandl | { |
290 | | | if [ $wcm_oneline -eq 0 ] |
291 | 5 | simandl | then |
292 | 14 | simandl | echo $wl_iwctxt | $wl_awkcmd '{print $1,$3,$4,$5" "}' |
293 | 15 | simandl | if [ $wcm_macoff -eq 1 ] |
294 | | | then |
295 | 16 | simandl | echo $wl_iwctxt | $wl_awkcmd '{print $6""$7,$12""$13" "}' |
296 | 15 | simandl | else |
297 | 16 | simandl | echo $wl_iwctxt | $wl_awkcmd '{print $6""$7,$10,$12""$13" "}' |
298 | 15 | simandl | fi |
299 | 5 | simandl | else |
300 | 16 | simandl | echo $wl_iwctxt | $wl_awkcmd '{print $1,$4,$5,$6""$7,$12""$13" "}' | sed 's/ [^": ]*:/ /g' |
301 | 5 | simandl | fi |
302 | 2 | simandl | wl_numcl=`ls $wl_hostap$wl_iface | grep -c 00` |
303 | | | echo $wlm_number_of_clients $wl_numcl |
304 | 13 | simandl | |
305 | 5 | simandl | wl_numcllast=$(($wl_numcllast + $wl_numcl)) |
306 | 13 | simandl | |
307 | 3 | simandl | for wl_mac in `ls $wl_hostap$wl_iface | grep 00 ` |
308 | 2 | simandl | do |
309 | 11 | simandl | wl_macparam=`cat $wl_hostap$wl_iface/$wl_mac | grep -E 'last_rx|last_tx' | sed 's/last_//g'` |
310 | 16 | simandl | 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'` |
312 | 14 | simandl | wl_silence=`echo $wl_macparam | $wl_awkcmd '{print $4}' | sed 's/silence=//g'` |
313 | 16 | simandl | wl_rate=`echo $wl_macparam | $wl_awkcmd '{print $8}'` |
314 | 11 | simandl | wl_cnt=$(($wl_signal - $wl_silence)) |
315 | 14 | simandl | wl_ipc=`cat $wl_arp | grep -i $wl_mac | $wl_awkcmd '{print $1}'` # IP adresa peeru z arp tabulky |
316 | 13 | simandl | |
317 | 14 | simandl | 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 |
327 | 13 | simandl | if [ $wcm_ppkts -eq 1 ] || [ $wcm_pkts -eq 1 ] |
328 | | | then |
329 | | | w_pkts |
330 | | | fi |
331 | | | |
332 | 5 | simandl | if [ $wcm_oneline -eq 0 ] |
333 | | | then |
334 | 15 | simandl | echo -n "${wlc_name}$wl_name${wlc_std} " |
335 | 5 | simandl | echo -n "${wlc_ip}$wl_ipc${wlc_std} " |
336 | 15 | simandl | 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} " |
346 | 16 | simandl | echo -n "$wl_rate " |
347 | 15 | simandl | if [ $wcm_rxtx -eq 0 ] |
348 | | | then |
349 | | | echo "" |
350 | | | else |
351 | 16 | simandl | echo $wl_macparam | $wl_awkcmd '{printf $1,$2" "}' |
352 | | | echo " $wl_jiffies" |
353 | 15 | simandl | fi |
354 | 5 | simandl | w_bar |
355 | | | else |
356 | 15 | simandl | 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} " |
361 | 16 | simandl | echo -n "$wl_name" |
362 | 5 | simandl | w_bar |
363 | | | fi |
364 | 4 | simandl | done |
365 | 11 | simandl | |
366 | | | echo |
367 | 2 | simandl | } # w_master |
368 | | | |
369 | | | ###################################################################### |
370 | | | w_iface() |
371 | 13 | simandl | { wl_iwctxt=`$wl_iwccmd $wl_iface 2>/dev/null | grep -v 'Device|Some|Extension' | sed 's/ Nick/_Nick/'` |
372 | 14 | simandl | wl_mode=`echo $wl_iwctxt | $wl_awkcmd '{print $5}' | sed 's/Mode://g'` |
373 | 2 | simandl | if [ "a$wl_mode" = "aManaged" ] |
374 | | | then |
375 | | | w_managed |
376 | 8 | simandl | elif [ "a$wl_mode" = "aAd-Hoc" ] |
377 | | | then |
378 | | | w_managed |
379 | 2 | simandl | 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 | | | ###################################################################### |
389 | 11 | simandl | w_version() |
390 | | | { |
391 | | | echo wifimon $wl_version |
392 | | | exit 0 |
393 | | | } |
394 | | | ###################################################################### |
395 | 5 | simandl | w_help() |
396 | | | { |
397 | 3 | simandl | echo Pouziti: wifimon [param] |
398 | | | echo param: |
399 | 11 | simandl | echo -v vypise verzi |
400 | 5 | simandl | echo -html generovani html stranky |
401 | 13 | simandl | echo -col barevny vypis na obrazovku |
402 | 5 | simandl | echo -once vypsani jen jednoho vypisu a pak program skonci |
403 | | | echo -oneline vypsani klientu na jednu linku |
404 | 15 | simandl | echo -threeline vypsani klienta na trech radcich |
405 | | | echo -rxtxoff vypnuti zobrazeni objemu prenesenych dat klienta |
406 | | | echo -macoff vypnuti zobrazeni MAC adres |
407 | 13 | simandl | 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 |
409 | 5 | simandl | echo -wlan0 -wlan1 -wlan2 vypise jen uvedene karty a to v danem poctu a poradi |
410 | 3 | simandl | echo bez parametru cyklicky vypis na obrazovku |
411 | 5 | simandl | exit 0 |
412 | | | } |
413 | | | ###################################################################### |
414 | | | ###################################################################### |
415 | 2 | simandl | |
416 | 5 | simandl | wl_unknown="" |
417 | | | wl_cnt=1 |
418 | | | wcm_clear=1 |
419 | | | wcm_once=0 |
420 | 11 | simandl | wcm_col=0 |
421 | 5 | simandl | wcm_oneline=0 |
422 | 15 | simandl | wcm_threeline=0 |
423 | 5 | simandl | wcm_html=0 |
424 | 15 | simandl | wcm_rxtx=1 |
425 | 13 | simandl | wcm_ppkts=0 |
426 | | | wcm_pkts=0 |
427 | 5 | simandl | wcm_ifc="" |
428 | 15 | simandl | wcm_macoff=0 |
429 | 5 | simandl | |
430 | 6 | simandl | # parsing input parameters |
431 | 5 | simandl | while [ "a$1" != "a" ] |
432 | | | do |
433 | | | case $1 in |
434 | 11 | simandl | -v) |
435 | | | w_version |
436 | | | ;; |
437 | 5 | simandl | -help) |
438 | | | w_help |
439 | | | ;; |
440 | | | -once) |
441 | | | wcm_once=1 |
442 | | | shift |
443 | | | ;; |
444 | | | -oneline) |
445 | | | wcm_oneline=1 |
446 | | | shift |
447 | | | ;; |
448 | 15 | simandl | -threeline) |
449 | | | wcm_threeline=1 |
450 | | | shift |
451 | | | ;; |
452 | 11 | simandl | -col) |
453 | | | wcm_col=1 |
454 | 5 | simandl | shift |
455 | | | ;; |
456 | | | -html) |
457 | | | wcm_html=1 |
458 | | | shift |
459 | | | ;; |
460 | 15 | simandl | -rxtxoff) |
461 | | | wcm_rxtx=0 |
462 | | | shift |
463 | | | ;; |
464 | 13 | simandl | -ppkts) |
465 | | | wcm_ppkts=1 |
466 | | | shift |
467 | | | ;; |
468 | | | -pkts) |
469 | | | wcm_pkts=1 |
470 | | | shift |
471 | | | ;; |
472 | 15 | simandl | -macoff) |
473 | | | wcm_macoff=1 |
474 | | | shift |
475 | | | ;; |
476 | 5 | simandl | *) |
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 |
492 | | | done |
493 | | | |
494 | 6 | simandl | # printing the list of bad parameters (if there are some) |
495 | 5 | simandl | if [ "a$wl_unknown" != "a" ] |
496 | | | then |
497 | | | echo "$wlm_unknown $wl_unknown" |
498 | | | w_help |
499 | | | fi |
500 | | | |
501 | 6 | simandl | # if no interface is selected then all available are choosen |
502 | 5 | simandl | if [ "a$wcm_ifc" = "a" ] |
503 | | | then |
504 | | | wcm_ifc=`ls $wl_hostap` |
505 | | | fi |
506 | | | |
507 | 6 | simandl | # setting for old and last same value to avoid double clear after start |
508 | | | wl_numcllast=0 |
509 | | | wl_numclold=0 |
510 | | | for wl_iface in $wcm_ifc |
511 | | | do |
512 | | | wl_numcl=`ls $wl_hostap$wl_iface | grep -c 00` |
513 | | | wl_numcllast=$(($wl_numcllast + $wl_numcl)) |
514 | | | done |
515 | | | wl_numclold=$wl_numcllast |
516 | | | |
517 | 11 | simandl | if [ $wcm_col -eq 0 ] |
518 | 6 | simandl | then |
519 | | | w_bw |
520 | 11 | simandl | else |
521 | 15 | simandl | if [ $wcm_html -eq 1 ] |
522 | | | then |
523 | | | w_colh |
524 | | | else |
525 | | | w_col |
526 | | | fi |
527 | 6 | simandl | fi |
528 | | | |
529 | 13 | simandl | if [ $wcm_html -eq 1 ] |
530 | | | then |
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 |
538 | | | fi |
539 | | | |
540 | 15 | simandl | #this is main loop and it will be executed forever |
541 | 6 | simandl | while [ 1 ] |
542 | 5 | simandl | do |
543 | 14 | simandl | |
544 | | | # when the number of associated klients has changed we will set for clear screen |
545 | 5 | simandl | if [ $wl_numcllast -ne $wl_numclold ] |
546 | | | then |
547 | | | wl_numclold=$wl_numcllast |
548 | | | wcm_clear=1 |
549 | | | fi |
550 | 14 | simandl | |
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 ] |
553 | 5 | simandl | then |
554 | 14 | simandl | echo -n $wl_clrcmde |
555 | 5 | simandl | wcm_clear=0 |
556 | | | fi |
557 | | | wl_numcllast=0 |
558 | 11 | simandl | |
559 | 14 | simandl | #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 |
566 | 13 | simandl | for wl_iface in $wcm_ifc |
567 | | | do |
568 | | | w_iface |
569 | | | done |
570 | | | |
571 | 14 | simandl | #when a single report is needed than we are exiting |
572 | 5 | simandl | if [ $wcm_once -eq 1 ] |
573 | | | then |
574 | | | exit 0 |
575 | | | fi |
576 | | | sleep 1 |
577 | 6 | simandl | done |
578 | 5 | simandl | |
579 | | | exit 0 |
580 | | | |