1 | 2 | simandl | #!/bin/bash |
2 | 3 | simandl | # authors : Petr Simandl www.simandl.cz |
3 | 14 | simandl | # : Fyzik, Covex, Tydyt |
4 | 21 | simandl | # release date : 11/09/2005 |
5 | 2 | simandl | # name : wifimon |
6 | 21 | simandl | # description : hostap and madwifi powered card monitoring |
7 | 2 | simandl | # license : GPL |
8 | 21 | simandl | ###################################################################### |
9 | 2 | simandl | |
10 | 21 | simandl | wl_version="0.5.5pre5" |
11 | 11 | simandl | |
12 | 21 | simandl | ###################################################################### |
13 | | | #custom settings |
14 | | | |
15 | 13 | simandl | PATH=$PATH:$HOME/bin:/bin:/sbin:/usr/bin:/usr/sbin:usr/local/bin:/usr/local/sbin |
16 | | | |
17 | 14 | simandl | wl_iwccmd=`which iwconfig` |
18 | 21 | simandl | wl_iwlcmd=`which iwlist` |
19 | 14 | simandl | wl_ifccmd=`which ifconfig` |
20 | | | wl_hnmcmd=`which hostname` |
21 | | | wl_awkcmd=`which awk` |
22 | | | |
23 | | | wl_tptcmde="[1;1H" |
24 | | | wl_clrcmde="[H[2J" |
25 | | | |
26 | 19 | simandl | wl_sysdev="/proc/sys/dev/" |
27 | 14 | simandl | wl_hostap="/proc/net/hostap/" |
28 | | | wl_wireless="/proc/net/wireless" |
29 | | | wl_arp="/proc/net/arp" |
30 | | | wl_dhcpcnf="/etc/dhcpd.conf" |
31 | | | wl_dhcplss="/var/lib/dhcp/dhcpd.leases" |
32 | 17 | simandl | # wl_dhcpcnf="/etc/dhcp3/dhcpd.conf" |
33 | | | # wl_dhcplss="/var/lib/dhcp3/dhcpd.leases" |
34 | 14 | simandl | |
35 | 21 | simandl | wl_header_refresh="<html><head><meta HTTP-EQUIV=\"Refresh\" CONTENT=\"15\"><title>Wifimon @ `$wl_hnmcmd`</title></head><body BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\"><pre>" |
36 | | | wl_header="<html><head><title>Wifimon @ `$wl_hnmcmd`</title></head><body BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\"><pre>" |
37 | | | wl_footer="</pre></body></html>" |
38 | 14 | simandl | |
39 | 21 | simandl | wlm_no_managed_or_master=" neni ani Master ani Managed..." |
40 | | | wlm_number_of_clients="Pocet asociovanych klientu : " |
41 | | | wlm_unknown="Nezname parametry nebo neplatne jmeno rozhrani : " |
42 | | | #wlm_no_managed_or_master=" is not Master or Managed..." |
43 | | | #wlm_number_of_clients="Number of associated clients : " |
44 | | | |
45 | | | wlch_signal="=" |
46 | | | wlch_noise="*" |
47 | | | |
48 | | | ###################################################################### |
49 | | | #testing basic setings |
50 | | | |
51 | 12 | simandl | if [ "$wl_iwccmd x" = " x" ] |
52 | | | then |
53 | | | echo "iwconfig not found" |
54 | | | exit 1 |
55 | | | fi |
56 | 2 | simandl | |
57 | 21 | simandl | if [ "$wl_iwlcmd x" = " x" ] |
58 | | | then |
59 | | | echo "iwlist not found" |
60 | | | exit 1 |
61 | | | fi |
62 | | | |
63 | 14 | simandl | if [ "$wl_ifccmd x" = " x" ] |
64 | | | then |
65 | | | echo "ifconfig not found" |
66 | | | exit 1 |
67 | | | fi |
68 | 4 | simandl | |
69 | 14 | simandl | if [ "$wl_hnmcmd x" = " x" ] |
70 | | | then |
71 | | | echo "hostname not found" |
72 | | | exit 1 |
73 | | | fi |
74 | | | |
75 | | | if [ "$wl_awkcmd x" = " x" ] |
76 | | | then |
77 | | | echo "awk not found" |
78 | | | exit 1 |
79 | | | fi |
80 | | | |
81 | | | if [ -e $wl_wireless ] |
82 | | | then |
83 | | | wl_nop=1 |
84 | | | else |
85 | | | echo "$wl_wireless not found" |
86 | | | exit 1 |
87 | | | fi |
88 | | | |
89 | | | if [ -e $wl_arp ] |
90 | | | then |
91 | | | wl_nop=1 |
92 | | | else |
93 | | | echo "$wl_arp not found" |
94 | | | exit 1 |
95 | | | fi |
96 | | | |
97 | | | if [ -e $wl_dhcpcnf ] |
98 | | | then |
99 | | | wl_nop=1 |
100 | | | else |
101 | | | echo "$wl_dhcpcnf not found" |
102 | | | wl_dhcpcnf="/dev/null" |
103 | | | fi |
104 | | | |
105 | | | if [ -e $wl_dhcplss ] |
106 | | | then |
107 | | | wl_nop=1 |
108 | | | else |
109 | | | echo "$wl_dhcplss not found" |
110 | | | wl_dhcplss="/dev/null" |
111 | | | fi |
112 | 21 | simandl | ###################################################################### |
113 | 14 | simandl | |
114 | 21 | simandl | if [ -d ${wl_hostap}wlan0 ] |
115 | | | then |
116 | | | wlf_hostap=1 |
117 | | | else |
118 | | | # echo "${wl_hostap}wlan0 not found" |
119 | | | wlf_hostap=0 |
120 | | | fi |
121 | 7 | simandl | |
122 | 21 | simandl | if [ -d ${wl_sysdev}ath0 ] |
123 | | | then |
124 | | | wlf_madwifi=1 |
125 | | | else |
126 | | | # echo "${wl_sysdev}ath0 not found" |
127 | | | wlf_madwifi=0 |
128 | | | fi |
129 | 7 | simandl | |
130 | 21 | simandl | if [ "$wlf_hostap" -eq 0 ] && [ "$wlf_madwifi" -eq 0 ] |
131 | | | then |
132 | | | echo "${wl_hostap}wlan0 not found" |
133 | | | echo "${wl_sysdev}ath0 not found" |
134 | | | exit 1 |
135 | | | fi |
136 | 11 | simandl | |
137 | 2 | simandl | ###################################################################### |
138 | 21 | simandl | # procedures |
139 | | | ###################################################################### |
140 | 11 | simandl | w_col() |
141 | 10 | simandl | { |
142 | 15 | simandl | wlc_red=`tput setaf 1` # ruda (Red) |
143 | | | wlc_green=`tput setaf 2` # zelena (Lime) |
144 | | | wlc_brown=`tput setaf 3` # zluta (Yellow) |
145 | | | wlc_blue=`tput setaf 4` # modra (Blue) |
146 | | | wlc_magenta=`tput setaf 5` # fialova (Fuchsia) |
147 | | | wlc_lblue=`tput setaf 6` # svetle modra (Aqua) |
148 | | | wlc_grey=`tput setaf 7` # bila (White) |
149 | 11 | simandl | wlc_std=`tput sgr0` |
150 | | | |
151 | 15 | simandl | wlc_pkts=$wlc_red # Rx,Tx info color |
152 | 11 | simandl | wlc_ip=$wlc_lblue # ip address color |
153 | | | wlc_mac=$wlc_magenta # mac address color |
154 | 15 | simandl | wlc_name=$wlc_magenta # host name color |
155 | 11 | simandl | wlc_sig=$wlc_red # signal number color |
156 | | | wlc_bar=$wlc_green # signal bar color |
157 | 15 | simandl | wlc_noise=$wlc_red # Signal noise color |
158 | 10 | simandl | } |
159 | | | ###################################################################### |
160 | 15 | simandl | w_colh() |
161 | | | { |
162 | | | wlh_pkts="Olive" # signal number color html |
163 | | | wlh_ip="Blue" # ip address color html |
164 | | | wlh_mac="Fuchsia" # mac address color html |
165 | | | wlh_name="Fuchsia" # Host name color html |
166 | | | wlh_sig="Red" # signal number color html |
167 | | | wlh_bar="Lime" # signal bar color html |
168 | | | wlh_noise="Red" # Signal noise color html |
169 | | | |
170 | | | wlc_pkts="<font color=\"$wlh_pkts\">" |
171 | | | wlc_ip="<font color=\"$wlh_ip\">" |
172 | | | wlc_mac="<font color=\"$wlh_mac\">" |
173 | | | wlc_name="<font color=\"$wlh_name\">" |
174 | | | wlc_sig="<font color=\"$wlh_sig\">" |
175 | | | wlc_bar="<font color=\"$wlh_bar\">" |
176 | | | wlc_noise="<font color=\"$wlh_noise\">" |
177 | | | wlc_std="</font>" |
178 | | | } |
179 | | | ###################################################################### |
180 | 4 | simandl | w_bw() |
181 | | | { |
182 | 15 | simandl | wlc_pkts="" |
183 | 6 | simandl | wlc_ip="" |
184 | | | wlc_mac="" |
185 | | | wlc_sig="" |
186 | | | wlc_bar="" |
187 | 15 | simandl | wlc_noise="" |
188 | 6 | simandl | wlc_std="" |
189 | 4 | simandl | } |
190 | | | ###################################################################### |
191 | 2 | simandl | w_bar() |
192 | | | { |
193 | 11 | simandl | wl_neg=`expr $wl_cnt \< 0 ` |
194 | | | if [ "$wl_neg" -eq 1 ] |
195 | | | then |
196 | 15 | simandl | echo -n "${wlc_noise}" |
197 | 11 | simandl | wl_cnt=$(($wl_cnt * -1 )) |
198 | | | wl_bar=$wlch_noise |
199 | | | else |
200 | 15 | simandl | echo -n "${wlc_bar}" |
201 | 11 | simandl | wl_bar=$wlch_signal |
202 | | | fi |
203 | 2 | simandl | until [ "$wl_cnt" -eq -1 ] |
204 | | | do |
205 | 11 | simandl | echo -n "$wl_bar" |
206 | 2 | simandl | wl_cnt=$(($wl_cnt - 1 )) |
207 | | | done |
208 | | | printf " \n" |
209 | 6 | simandl | echo -n "${wlc_std}" |
210 | 11 | simandl | # tput sgr0 |
211 | 2 | simandl | } # w_bar |
212 | | | |
213 | | | ###################################################################### |
214 | 13 | simandl | w_pkts() |
215 | | | { |
216 | | | wl_macpkts=`cat $wl_hostap$wl_iface/$wl_mac | grep -E 'rx\[|tx\[' | sed 's/=/ /g'` |
217 | 14 | simandl | wl_nt1=`echo $wl_macpkts | $wl_awkcmd '{print $2}'` |
218 | | | wl_nt2=`echo $wl_macpkts | $wl_awkcmd '{print $4}'` |
219 | | | wl_nt5=`echo $wl_macpkts | $wl_awkcmd '{print $6}'` |
220 | | | wl_nt11=`echo $wl_macpkts | $wl_awkcmd '{print $8}'` |
221 | | | wl_nr1=`echo $wl_macpkts | $wl_awkcmd '{print $10}'` |
222 | | | wl_nr2=`echo $wl_macpkts | $wl_awkcmd '{print $12}'` |
223 | | | wl_nr5=`echo $wl_macpkts | $wl_awkcmd '{print $14}'` |
224 | | | wl_nr11=`echo $wl_macpkts | $wl_awkcmd '{print $16}'` |
225 | 13 | simandl | |
226 | | | if [ $wcm_ppkts -eq 1 ] |
227 | | | then |
228 | | | wl_pksize=$((98)) |
229 | | | wl_nt=$(($wl_nt1 + $wl_nt2 + wl_nt5 + wl_nt11)) |
230 | | | if [ "$wl_nt1" -eq 0 ] |
231 | | | then |
232 | | | wl_nt1n="00" |
233 | | | else |
234 | | | wl_nt1n=$(($wl_pksize * $wl_nt1 / $wl_nt + 1)) |
235 | | | [ "$wl_nt1n" -lt 10 ] && wl_nt1n="0"$wl_nt1n |
236 | | | fi |
237 | | | if [ "$wl_nt2" -eq 0 ] |
238 | | | then |
239 | | | wl_nt2n="00" |
240 | | | else |
241 | | | wl_nt2n=$(($wl_pksize * $wl_nt2 / $wl_nt + 1)) |
242 | | | [ "$wl_nt2n" -lt 10 ] && wl_nt2n="0"$wl_nt2n |
243 | | | fi |
244 | | | if [ "$wl_nt5" -eq 0 ] |
245 | | | then |
246 | | | wl_nt5n="00" |
247 | | | else |
248 | | | wl_nt5n=$(($wl_pksize * $wl_nt5 / $wl_nt + 1)) |
249 | | | [ "$wl_nt5n" -lt 10 ] && wl_nt5n="0"$wl_nt5n |
250 | | | fi |
251 | | | if [ "$wl_nt11" -eq 0 ] |
252 | | | then |
253 | | | wl_nt11n="00" |
254 | | | else |
255 | | | wl_nt11n=$(($wl_pksize * $wl_nt11 / $wl_nt + 1)) |
256 | | | [ "$wl_nt11n" -lt 10 ] && wl_nt11n="0"$wl_nt11n |
257 | | | fi |
258 | | | wl_nr=$((1 + $wl_nr1 + $wl_nr2 + wl_nr5 + wl_nr11)) |
259 | | | if [ "$wl_nr1" -eq 0 ] |
260 | | | then |
261 | | | wl_nr1n="00" |
262 | | | else |
263 | | | wl_nr1n=$(($wl_pksize * $wl_nr1 / $wl_nr + 1)) |
264 | | | [ "$wl_nr1n" -lt 10 ] && wl_nr1n="0"$wl_nr1n |
265 | | | fi |
266 | | | if [ "$wl_nr2" -eq 0 ] |
267 | | | then |
268 | | | wl_nr2n="00" |
269 | | | else |
270 | | | wl_nr2n=$(($wl_pksize * $wl_nr2 / $wl_nr + 1)) |
271 | | | [ "$wl_nr2n" -lt 10 ] && wl_nr2n="0"$wl_nr2n |
272 | | | fi |
273 | | | if [ "$wl_nr5" -eq 0 ] |
274 | | | then |
275 | | | wl_nr5n="00" |
276 | | | else |
277 | | | wl_nr5n=$(($wl_pksize * $wl_nr5 / $wl_nr + 1)) |
278 | | | [ "$wl_nr5n" -lt 10 ] && wl_nr5n="0"$wl_nr5n |
279 | | | fi |
280 | | | if [ "$wl_nr11" -eq 0 ] |
281 | | | then |
282 | | | wl_nr11n="00" |
283 | | | else |
284 | | | wl_nr11n=$(($wl_pksize * $wl_nr11 / $wl_nr + 1)) |
285 | | | [ "$wl_nr11n" -lt 10 ] && wl_nr11n="0"$wl_nr11n |
286 | | | fi |
287 | 15 | simandl | echo -n "Tx"${wlc_pkts} $wl_nt1n $wl_nt2n $wl_nt5n $wl_nt11n ${wlc_std}"" |
288 | | | echo -n "Rx"${wlc_pkts} $wl_nr1n $wl_nr2n $wl_nr5n $wl_nr11n ${wlc_std}"" |
289 | 13 | simandl | fi |
290 | | | |
291 | | | [ $wcm_pkts -eq 1 ] && echo -n "Tx" $wl_nt1 $wl_nt2 $wl_nt5 $wl_nt11 "Rx" $wl_nr1 $wl_nr2 $wl_nr5 $wl_nr11 "" |
292 | | | |
293 | | | } # w_pkts |
294 | | | ###################################################################### |
295 | 17 | simandl | w_managed() |
296 | | | { echo $wl_iwctxt | $wl_awkcmd '{print $1,$3,$4,$5" "}' |
297 | 18 | 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 |
298 | 15 | simandl | |
299 | 18 | simandl | if [ $wcm_macoff -eq 0 ] |
300 | 15 | simandl | then |
301 | 19 | simandl | wl_mac=`echo -n $wl_iwctxt | $wl_awkcmd '{print $9}'` |
302 | 18 | simandl | echo -n "${wlc_mac}$wl_mac${wlc_std} " |
303 | 15 | simandl | fi |
304 | 18 | simandl | echo $wl_iwctxt | $wl_awkcmd '{print $6,$10" "}' |
305 | 15 | simandl | |
306 | 14 | simandl | wl_wtxt=`cat $wl_wireless | grep $wl_iface | $wl_awkcmd '{print $3,$4,$5}' | sed 's/\.//g'` |
307 | | | wl_quality=`echo $wl_wtxt | $wl_awkcmd '{print $1}'` |
308 | | | wl_signal=`echo $wl_wtxt | $wl_awkcmd '{print $2}'` |
309 | 2 | simandl | wl_signal=$(($wl_signal - 256)) |
310 | 14 | simandl | wl_noise=`echo $wl_wtxt | $wl_awkcmd '{print $3}'` |
311 | 2 | simandl | wl_noise=$(($wl_noise - 256)) |
312 | 5 | simandl | echo "Quality:${wlc_sig}$wl_quality${wlc_std}/92 Signal level:$wl_signal Noise level:$wl_noise " |
313 | 2 | simandl | wl_cnt=$wl_quality |
314 | | | w_bar |
315 | | | echo |
316 | | | } # w_managed |
317 | | | |
318 | | | ###################################################################### |
319 | | | w_master() |
320 | 17 | simandl | { if [ $wcm_oneline -eq 0 ] |
321 | 21 | simandl | then |
322 | | | echo $wl_iwctxt | $wl_awkcmd '{print $1,$3,$4,$5" "}' |
323 | | | if [ $wcm_macoff -eq 1 ] |
324 | | | then |
325 | | | echo $wl_iwctxt | $wl_awkcmd '{print $6,$11" "}' |
326 | | | else |
327 | | | echo $wl_iwctxt | $wl_awkcmd '{print $6,$9,$11" "}' |
328 | | | fi |
329 | | | else |
330 | | | echo $wl_iwctxt | $wl_awkcmd '{print $1,$4,$5,$6,$11" "}' | sed 's/ [^": ]*:/ /g' |
331 | | | fi |
332 | | | |
333 | | | if [ -d $wl_hostap$wl_iface ] |
334 | 15 | simandl | then |
335 | 21 | simandl | wl_numcl=`ls $wl_hostap$wl_iface | grep -c 00` |
336 | | | wl_macs=`ls $wl_hostap$wl_iface | grep 00` |
337 | 5 | simandl | fi |
338 | 21 | simandl | |
339 | | | if [ -d $wl_sysdev$wl_iface ] |
340 | | | then |
341 | | | wl_numcl=`$wl_iwlcmd $wl_iface peers | grep -c 00` |
342 | | | wl_macs=`iwlist $wl_iface peers | grep 00 | awk '{print $1}'` |
343 | | | fi |
344 | | | |
345 | 2 | simandl | echo $wlm_number_of_clients $wl_numcl |
346 | 13 | simandl | |
347 | 5 | simandl | wl_numcllast=$(($wl_numcllast + $wl_numcl)) |
348 | 13 | simandl | |
349 | 21 | simandl | for wl_mac in $wl_macs |
350 | 2 | simandl | do |
351 | 21 | simandl | if [ -d $wl_hostap$wl_iface ] |
352 | | | then |
353 | | | wl_macparam=`cat $wl_hostap$wl_iface/$wl_mac | grep -E 'last_rx|last_tx' | sed 's/last_//g'` |
354 | | | wl_signal=`echo $wl_macparam | $wl_awkcmd '{print $6}' | sed 's/signal=//g'` |
355 | | | wl_silence=`echo $wl_macparam | $wl_awkcmd '{print $4}' | sed 's/silence=//g'` |
356 | | | fi |
357 | | | |
358 | | | if [ -d $wl_sysdev$wl_iface ] |
359 | | | then |
360 | | | wl_macparam=`$wl_iwlcmd $wl_iface peers | grep $wl_mac` |
361 | | | wl_signal=`echo $wl_macparam | $wl_awkcmd '{print $5}' | sed 's/level://g'` |
362 | | | wl_silence=`echo $wl_macparam | $wl_awkcmd '{print $8}' | sed 's/level://g'` |
363 | | | fi |
364 | | | |
365 | 11 | simandl | wl_cnt=$(($wl_signal - $wl_silence)) |
366 | 14 | simandl | wl_ipc=`cat $wl_arp | grep -i $wl_mac | $wl_awkcmd '{print $1}'` # IP adresa peeru z arp tabulky |
367 | 13 | simandl | |
368 | 14 | simandl | wl_name=`cat $wl_dhcpcnf | grep -i $wl_mac | $wl_awkcmd '{print $2}'` |
369 | | | if [ "$wl_name" = "ethernet" ] || [ "$wl_name" = "" ] |
370 | | | then |
371 | | | 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}'` |
372 | | | if [ "$wl_name" = "" ] |
373 | | | then |
374 | 17 | simandl | wl_name=`cat $wl_dhcplss | grep -i $wl_mac -A 2 | grep -i client-hostname | $wl_awkcmd '{print$2}'` |
375 | 14 | simandl | wl_name=`echo $wl_name | $wl_awkcmd '{print$1}' ` |
376 | | | fi |
377 | | | fi |
378 | 21 | simandl | if [ $wcm_ppkts -eq 1 ] || [ $wcm_pkts -eq 1 ] && [ -d $wl_hostap$wl_iface ] |
379 | 13 | simandl | then |
380 | | | w_pkts |
381 | | | fi |
382 | | | |
383 | 5 | simandl | if [ $wcm_oneline -eq 0 ] |
384 | | | then |
385 | 15 | simandl | echo -n "${wlc_name}$wl_name${wlc_std} " |
386 | 5 | simandl | echo -n "${wlc_ip}$wl_ipc${wlc_std} " |
387 | 15 | simandl | if [ $wcm_macoff -eq 0 ] |
388 | | | then |
389 | | | echo -n "${wlc_mac}$wl_mac${wlc_std} " |
390 | | | fi |
391 | | | if [ $wcm_threeline -eq 1 ] |
392 | | | then |
393 | | | echo "" |
394 | | | echo -n " " |
395 | | | fi |
396 | | | echo -n "Signal ${wlc_sig}$wl_cnt${wlc_std} " |
397 | | | if [ $wcm_rxtx -eq 0 ] |
398 | | | then |
399 | | | echo "" |
400 | | | else |
401 | 21 | simandl | if [ -d $wl_hostap$wl_iface ] |
402 | | | then |
403 | | | echo $wl_macparam | $wl_awkcmd '{print $1,$2" "}' |
404 | | | else |
405 | | | echo "" |
406 | | | fi |
407 | 15 | simandl | fi |
408 | 5 | simandl | w_bar |
409 | | | else |
410 | 15 | simandl | if [ $wcm_macoff -eq 0 ] |
411 | | | then |
412 | | | echo -n "${wlc_mac}$wl_mac${wlc_std} " |
413 | | | fi |
414 | | | echo -n "${wlc_sig}$wl_cnt${wlc_std} " |
415 | 17 | simandl | echo -n "$wl_name " |
416 | 5 | simandl | w_bar |
417 | | | fi |
418 | 4 | simandl | done |
419 | 11 | simandl | |
420 | | | echo |
421 | 2 | simandl | } # w_master |
422 | | | |
423 | | | ###################################################################### |
424 | | | w_iface() |
425 | 18 | simandl | { wl_iwctxt=`$wl_iwccmd $wl_iface 2>/dev/null | grep -v 'Device|Some|Extension' | sed 's/ Nick/_Nick/' | sed 's/Access Point/Access_Point/'` |
426 | 14 | simandl | wl_mode=`echo $wl_iwctxt | $wl_awkcmd '{print $5}' | sed 's/Mode://g'` |
427 | 2 | simandl | if [ "a$wl_mode" = "aManaged" ] |
428 | | | then |
429 | | | w_managed |
430 | 8 | simandl | elif [ "a$wl_mode" = "aAd-Hoc" ] |
431 | | | then |
432 | | | w_managed |
433 | 2 | simandl | elif [ "a$wl_mode" = "aMaster" ] |
434 | | | then |
435 | | | w_master |
436 | | | else |
437 | | | echo $wl_iface $wlm_no_managed_or_master |
438 | | | echo |
439 | | | fi |
440 | | | } |
441 | | | |
442 | | | ###################################################################### |
443 | 11 | simandl | w_version() |
444 | | | { |
445 | | | echo wifimon $wl_version |
446 | | | exit 0 |
447 | | | } |
448 | | | ###################################################################### |
449 | 5 | simandl | w_help() |
450 | | | { |
451 | 21 | simandl | echo Monitorovani wifi karet pouzivajicich hostap nebo madwifi ovladace |
452 | 3 | simandl | echo Pouziti: wifimon [param] |
453 | | | echo param: |
454 | 11 | simandl | echo -v vypise verzi |
455 | 5 | simandl | echo -html generovani html stranky |
456 | 13 | simandl | echo -col barevny vypis na obrazovku |
457 | 5 | simandl | echo -once vypsani jen jednoho vypisu a pak program skonci |
458 | | | echo -oneline vypsani klientu na jednu linku |
459 | 15 | simandl | echo -threeline vypsani klienta na trech radcich |
460 | 21 | simandl | echo -macoff vypnuti zobrazeni MAC adres |
461 | | | echo -wlan0 -ath0 -wlan2 vypise jen uvedene karty a to v danem poctu a poradi |
462 | | | echo nasledujici parametry ovlivnuji jen karty s hostap: |
463 | 15 | simandl | echo -rxtxoff vypnuti zobrazeni objemu prenesenych dat klienta |
464 | 13 | simandl | echo -ppkts vypsani procentniho pomeru 1M, 2M, 5.5M a 11M paketu pro jednotlive klienty |
465 | | | echo -pkts vypsani poctu 1M, 2M, 5.5M a 11M paketu pro jednotlive klienty |
466 | 3 | simandl | echo bez parametru cyklicky vypis na obrazovku |
467 | 5 | simandl | exit 0 |
468 | | | } |
469 | | | ###################################################################### |
470 | | | ###################################################################### |
471 | 2 | simandl | |
472 | 5 | simandl | wl_unknown="" |
473 | | | wl_cnt=1 |
474 | | | wcm_clear=1 |
475 | | | wcm_once=0 |
476 | 11 | simandl | wcm_col=0 |
477 | 5 | simandl | wcm_oneline=0 |
478 | 15 | simandl | wcm_threeline=0 |
479 | 5 | simandl | wcm_html=0 |
480 | 15 | simandl | wcm_rxtx=1 |
481 | 13 | simandl | wcm_ppkts=0 |
482 | | | wcm_pkts=0 |
483 | 5 | simandl | wcm_ifc="" |
484 | 15 | simandl | wcm_macoff=0 |
485 | 5 | simandl | |
486 | 6 | simandl | # parsing input parameters |
487 | 5 | simandl | while [ "a$1" != "a" ] |
488 | | | do |
489 | | | case $1 in |
490 | 11 | simandl | -v) |
491 | | | w_version |
492 | | | ;; |
493 | 5 | simandl | -help) |
494 | | | w_help |
495 | | | ;; |
496 | | | -once) |
497 | | | wcm_once=1 |
498 | | | shift |
499 | | | ;; |
500 | | | -oneline) |
501 | | | wcm_oneline=1 |
502 | | | shift |
503 | | | ;; |
504 | 15 | simandl | -threeline) |
505 | | | wcm_threeline=1 |
506 | | | shift |
507 | | | ;; |
508 | 11 | simandl | -col) |
509 | | | wcm_col=1 |
510 | 5 | simandl | shift |
511 | | | ;; |
512 | | | -html) |
513 | | | wcm_html=1 |
514 | | | shift |
515 | | | ;; |
516 | 15 | simandl | -rxtxoff) |
517 | | | wcm_rxtx=0 |
518 | | | shift |
519 | | | ;; |
520 | 13 | simandl | -ppkts) |
521 | | | wcm_ppkts=1 |
522 | | | shift |
523 | | | ;; |
524 | | | -pkts) |
525 | | | wcm_pkts=1 |
526 | | | shift |
527 | | | ;; |
528 | 15 | simandl | -macoff) |
529 | | | wcm_macoff=1 |
530 | | | shift |
531 | | | ;; |
532 | 5 | simandl | *) |
533 | | | wl_flg=0 |
534 | 19 | simandl | #wlan check |
535 | 21 | simandl | if [ $wlf_hostap -eq 1 ] |
536 | 5 | simandl | then |
537 | 21 | simandl | for wl_iface in `ls $wl_hostap` |
538 | | | do |
539 | | | if [ "a-$wl_iface" = "a$1" ] |
540 | | | then |
541 | | | wcm_ifc="$wcm_ifc $wl_iface" |
542 | | | wl_flg=1 |
543 | | | fi |
544 | | | done |
545 | | | fi |
546 | 19 | simandl | # ath check |
547 | 21 | simandl | if [ $wlf_madwifi -eq 1 ] |
548 | 19 | simandl | then |
549 | 21 | simandl | for wl_iface in `ls $wl_sysdev | grep "ath[0-9]"` |
550 | | | do |
551 | | | if [ "a-$wl_iface" = "a$1" ] |
552 | | | then |
553 | | | wcm_ifc="$wcm_ifc $wl_iface" |
554 | | | wl_flg=1 |
555 | | | fi |
556 | | | done |
557 | | | fi |
558 | 5 | simandl | if [ $wl_flg -eq 0 ] |
559 | 21 | simandl | then |
560 | | | wl_unknown="$wl_unknown$1 " |
561 | 5 | simandl | fi |
562 | | | shift |
563 | | | esac |
564 | | | done |
565 | | | |
566 | 6 | simandl | # printing the list of bad parameters (if there are some) |
567 | 5 | simandl | if [ "a$wl_unknown" != "a" ] |
568 | | | then |
569 | | | echo "$wlm_unknown $wl_unknown" |
570 | | | w_help |
571 | | | fi |
572 | 6 | simandl | # if no interface is selected then all available are choosen |
573 | 5 | simandl | if [ "a$wcm_ifc" = "a" ] |
574 | | | then |
575 | 21 | simandl | if [ $wlf_hostap -eq 1 ] |
576 | | | then |
577 | | | wcm_ifc=`ls $wl_hostap ` |
578 | | | fi |
579 | | | if [ $wlf_madwifi -eq 1 ] |
580 | | | then |
581 | | | wcm_ifc=`echo $wcm_ifc ; ls $wl_sysdev | grep "ath[0-9]"` |
582 | | | fi |
583 | 5 | simandl | fi |
584 | | | |
585 | 6 | simandl | # setting for old and last same value to avoid double clear after start |
586 | | | wl_numcllast=0 |
587 | | | wl_numclold=0 |
588 | | | for wl_iface in $wcm_ifc |
589 | | | do |
590 | 21 | simandl | if [ -d $wl_hostap$wl_iface ] |
591 | | | then |
592 | | | wl_numcl=`ls $wl_hostap$wl_iface | grep -c 00` |
593 | | | wl_numcllast=$(($wl_numcllast + $wl_numcl)) |
594 | | | fi |
595 | | | if [ -d $wl_sysdev$wl_iface ] |
596 | | | then |
597 | | | wl_mode=`$wl_iwccmd $wl_iface | grep Mode | $wl_awkcmd '{print $1}' | sed 's/Mode://g'` |
598 | | | if [ "a$wl_mode" = "aMaster" ] |
599 | | | then |
600 | | | wl_numcl=`$wl_iwlcmd $wl_iface peers | grep -c 00` |
601 | | | wl_numcllast=$(($wl_numcllast + $wl_numcl)) |
602 | | | fi |
603 | | | fi |
604 | 6 | simandl | done |
605 | | | wl_numclold=$wl_numcllast |
606 | | | |
607 | 11 | simandl | if [ $wcm_col -eq 0 ] |
608 | 6 | simandl | then |
609 | | | w_bw |
610 | 11 | simandl | else |
611 | 15 | simandl | if [ $wcm_html -eq 1 ] |
612 | | | then |
613 | | | w_colh |
614 | | | else |
615 | | | w_col |
616 | | | fi |
617 | 6 | simandl | fi |
618 | | | |
619 | 13 | simandl | if [ $wcm_html -eq 1 ] |
620 | | | then |
621 | | | [ $wcm_once -eq 1 ] && echo $wl_header || echo $wl_header_refresh |
622 | | | for wl_iface in $wcm_ifc |
623 | | | do |
624 | | | w_iface |
625 | | | done |
626 | | | echo $wl_footer |
627 | | | exit 0 |
628 | | | fi |
629 | | | |
630 | 15 | simandl | #this is main loop and it will be executed forever |
631 | 6 | simandl | while [ 1 ] |
632 | 5 | simandl | do |
633 | 14 | simandl | |
634 | | | # when the number of associated klients has changed we will set for clear screen |
635 | 5 | simandl | if [ $wl_numcllast -ne $wl_numclold ] |
636 | | | then |
637 | | | wl_numclold=$wl_numcllast |
638 | | | wcm_clear=1 |
639 | | | fi |
640 | 14 | simandl | |
641 | | | #if it is set for clear screen we will do it except we produce single report |
642 | | | if [ $wcm_clear -eq 1 -a $wcm_once -eq 0 ] |
643 | 5 | simandl | then |
644 | 14 | simandl | echo -n $wl_clrcmde |
645 | 5 | simandl | wcm_clear=0 |
646 | | | fi |
647 | | | wl_numcllast=0 |
648 | 11 | simandl | |
649 | 14 | simandl | #for cyclic report we are trying to set cursor to the top left screen corner |
650 | | | if [ $wcm_once -eq 0 ] |
651 | | | then |
652 | | | echo -n $wl_tptcmde |
653 | | | fi |
654 | | | |
655 | | | #make report for all desired interfaces |
656 | 13 | simandl | for wl_iface in $wcm_ifc |
657 | | | do |
658 | | | w_iface |
659 | | | done |
660 | | | |
661 | 14 | simandl | #when a single report is needed than we are exiting |
662 | 5 | simandl | if [ $wcm_once -eq 1 ] |
663 | | | then |
664 | | | exit 0 |
665 | | | fi |
666 | | | sleep 1 |
667 | 6 | simandl | done |
668 | 5 | simandl | |
669 | | | exit 0 |
670 | | | |