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