1 | 2 | simandl | #!/bin/bash |
2 | 3 | simandl | # authors : Petr Simandl www.simandl.cz |
3 | 22 | simandl | # : Fyzik, Covex, Tydyt, Thunder.m |
4 | 30 | simandl | # release date : 12/04/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 | 30 | simandl | wl_version="0.5.7pre5" |
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 | 28 | simandl | echo -n $wl_macparam | $wl_awkcmd '{print $1,$2" "}' |
440 | 21 | simandl | fi |
441 | 28 | simandl | if [ -d $wl_madwifi$wl_iface ] |
442 | | | then |
443 | | | echo -n $wl_rxtx |
444 | | | fi |
445 | | | echo "" |
446 | 15 | simandl | fi |
447 | 5 | simandl | w_bar |
448 | | | else |
449 | 15 | simandl | if [ $wcm_macoff -eq 0 ] |
450 | | | then |
451 | | | echo -n "${wlc_mac}$wl_mac${wlc_std} " |
452 | | | fi |
453 | | | echo -n "${wlc_sig}$wl_cnt${wlc_std} " |
454 | 17 | simandl | echo -n "$wl_name " |
455 | 5 | simandl | w_bar |
456 | | | fi |
457 | 4 | simandl | done |
458 | 11 | simandl | |
459 | | | echo |
460 | 2 | simandl | } # w_master |
461 | | | |
462 | | | ###################################################################### |
463 | | | w_iface() |
464 | 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/'` |
465 | 14 | simandl | wl_mode=`echo $wl_iwctxt | $wl_awkcmd '{print $5}' | sed 's/Mode://g'` |
466 | 2 | simandl | if [ "a$wl_mode" = "aManaged" ] |
467 | | | then |
468 | | | w_managed |
469 | 8 | simandl | elif [ "a$wl_mode" = "aAd-Hoc" ] |
470 | | | then |
471 | | | w_managed |
472 | 2 | simandl | elif [ "a$wl_mode" = "aMaster" ] |
473 | | | then |
474 | | | w_master |
475 | | | else |
476 | 24 | simandl | echo $wl_iface $wlm_no_managed_or_master |
477 | 2 | simandl | echo |
478 | | | fi |
479 | | | } |
480 | | | |
481 | | | ###################################################################### |
482 | 11 | simandl | w_version() |
483 | | | { |
484 | | | echo wifimon $wl_version |
485 | | | exit 0 |
486 | | | } |
487 | | | ###################################################################### |
488 | 5 | simandl | w_help() |
489 | | | { |
490 | 21 | simandl | echo Monitorovani wifi karet pouzivajicich hostap nebo madwifi ovladace |
491 | 3 | simandl | echo Pouziti: wifimon [param] |
492 | | | echo param: |
493 | 11 | simandl | echo -v vypise verzi |
494 | 5 | simandl | echo -html generovani html stranky |
495 | 13 | simandl | echo -col barevny vypis na obrazovku |
496 | 5 | simandl | echo -once vypsani jen jednoho vypisu a pak program skonci |
497 | | | echo -oneline vypsani klientu na jednu linku |
498 | 15 | simandl | echo -threeline vypsani klienta na trech radcich |
499 | 21 | simandl | echo -macoff vypnuti zobrazeni MAC adres |
500 | | | echo -wlan0 -ath0 -wlan2 vypise jen uvedene karty a to v danem poctu a poradi |
501 | | | echo nasledujici parametry ovlivnuji jen karty s hostap: |
502 | 15 | simandl | echo -rxtxoff vypnuti zobrazeni objemu prenesenych dat klienta |
503 | 13 | simandl | echo -ppkts vypsani procentniho pomeru 1M, 2M, 5.5M a 11M paketu pro jednotlive klienty |
504 | | | echo -pkts vypsani poctu 1M, 2M, 5.5M a 11M paketu pro jednotlive klienty |
505 | 3 | simandl | echo bez parametru cyklicky vypis na obrazovku |
506 | 5 | simandl | exit 0 |
507 | | | } |
508 | | | ###################################################################### |
509 | | | ###################################################################### |
510 | 2 | simandl | |
511 | 5 | simandl | wl_unknown="" |
512 | | | wl_cnt=1 |
513 | | | wcm_clear=1 |
514 | | | wcm_once=0 |
515 | 24 | simandl | wcm_col=0 |
516 | 5 | simandl | wcm_oneline=0 |
517 | 15 | simandl | wcm_threeline=0 |
518 | 5 | simandl | wcm_html=0 |
519 | 15 | simandl | wcm_rxtx=1 |
520 | 13 | simandl | wcm_ppkts=0 |
521 | | | wcm_pkts=0 |
522 | 5 | simandl | wcm_ifc="" |
523 | 15 | simandl | wcm_macoff=0 |
524 | 5 | simandl | |
525 | 6 | simandl | # parsing input parameters |
526 | 5 | simandl | while [ "a$1" != "a" ] |
527 | | | do |
528 | | | case $1 in |
529 | 11 | simandl | -v) |
530 | | | w_version |
531 | | | ;; |
532 | 5 | simandl | -help) |
533 | | | w_help |
534 | | | ;; |
535 | | | -once) |
536 | | | wcm_once=1 |
537 | | | shift |
538 | | | ;; |
539 | | | -oneline) |
540 | | | wcm_oneline=1 |
541 | | | shift |
542 | | | ;; |
543 | 15 | simandl | -threeline) |
544 | | | wcm_threeline=1 |
545 | | | shift |
546 | | | ;; |
547 | 11 | simandl | -col) |
548 | 24 | simandl | wcm_col=1 |
549 | 5 | simandl | shift |
550 | | | ;; |
551 | | | -html) |
552 | | | wcm_html=1 |
553 | | | shift |
554 | | | ;; |
555 | 15 | simandl | -rxtxoff) |
556 | | | wcm_rxtx=0 |
557 | | | shift |
558 | | | ;; |
559 | 13 | simandl | -ppkts) |
560 | | | wcm_ppkts=1 |
561 | | | shift |
562 | | | ;; |
563 | | | -pkts) |
564 | | | wcm_pkts=1 |
565 | | | shift |
566 | | | ;; |
567 | 15 | simandl | -macoff) |
568 | | | wcm_macoff=1 |
569 | | | shift |
570 | | | ;; |
571 | 5 | simandl | *) |
572 | | | wl_flg=0 |
573 | 19 | simandl | #wlan check |
574 | 21 | simandl | if [ $wlf_hostap -eq 1 ] |
575 | 5 | simandl | then |
576 | 21 | simandl | for wl_iface in `ls $wl_hostap` |
577 | | | do |
578 | 24 | simandl | if [ "a-$wl_iface" = "a$1" ] |
579 | 21 | simandl | then |
580 | | | wcm_ifc="$wcm_ifc $wl_iface" |
581 | | | wl_flg=1 |
582 | | | fi |
583 | | | done |
584 | | | fi |
585 | 19 | simandl | # ath check |
586 | 21 | simandl | if [ $wlf_madwifi -eq 1 ] |
587 | 19 | simandl | then |
588 | 27 | simandl | for wl_iface in `ls $wl_madwifi | grep "ath[0-9]"` |
589 | 21 | simandl | do |
590 | 24 | simandl | if [ "a-$wl_iface" = "a$1" ] |
591 | 21 | simandl | then |
592 | | | wcm_ifc="$wcm_ifc $wl_iface" |
593 | | | wl_flg=1 |
594 | | | fi |
595 | | | done |
596 | | | fi |
597 | 5 | simandl | if [ $wl_flg -eq 0 ] |
598 | 21 | simandl | then |
599 | | | wl_unknown="$wl_unknown$1 " |
600 | 5 | simandl | fi |
601 | | | shift |
602 | | | esac |
603 | | | done |
604 | | | |
605 | 6 | simandl | # printing the list of bad parameters (if there are some) |
606 | 5 | simandl | if [ "a$wl_unknown" != "a" ] |
607 | | | then |
608 | | | echo "$wlm_unknown $wl_unknown" |
609 | | | w_help |
610 | | | fi |
611 | 29 | simandl | |
612 | 6 | simandl | # if no interface is selected then all available are choosen |
613 | 5 | simandl | if [ "a$wcm_ifc" = "a" ] |
614 | | | then |
615 | 21 | simandl | if [ $wlf_hostap -eq 1 ] |
616 | | | then |
617 | | | wcm_ifc=`ls $wl_hostap ` |
618 | | | fi |
619 | | | if [ $wlf_madwifi -eq 1 ] |
620 | | | then |
621 | 29 | simandl | wcm_ifc=`echo $wcm_ifc ; ls $wl_sysdev | grep "ath[0-9]" ; ls $wl_madwifi | grep "ath[0-9]"` |
622 | 21 | simandl | fi |
623 | 5 | simandl | fi |
624 | | | |
625 | 6 | simandl | # setting for old and last same value to avoid double clear after start |
626 | | | wl_numcllast=0 |
627 | | | wl_numclold=0 |
628 | | | for wl_iface in $wcm_ifc |
629 | | | do |
630 | 21 | simandl | if [ -d $wl_hostap$wl_iface ] |
631 | | | then |
632 | | | wl_numcl=`ls $wl_hostap$wl_iface | grep -c 00` |
633 | | | wl_numcllast=$(($wl_numcllast + $wl_numcl)) |
634 | | | fi |
635 | 27 | simandl | if [ -d $wl_madwifi$wl_iface ] |
636 | 21 | simandl | then |
637 | 24 | simandl | wl_mode=`$wl_iwccmd $wl_iface | grep Mode | $wl_awkcmd '{print $1}' | sed 's/Mode://g'` |
638 | 21 | simandl | if [ "a$wl_mode" = "aMaster" ] |
639 | | | then |
640 | 28 | simandl | wl_numcl=`$wl_wlancf $wl_iface list sta | grep -c ^[0..9]` |
641 | 21 | simandl | wl_numcllast=$(($wl_numcllast + $wl_numcl)) |
642 | | | fi |
643 | | | fi |
644 | 29 | simandl | if [ -d $wl_sysdev$wl_iface ] |
645 | | | then |
646 | | | wl_mode=`$wl_iwccmd $wl_iface | grep Mode | $wl_awkcmd '{print $1}' | sed 's/Mode://g'` |
647 | | | if [ "a$wl_mode" = "aMaster" ] |
648 | | | then |
649 | | | wl_numcl=`$wl_iwlcmd $wl_iface peers | grep -c 00` |
650 | | | wl_numcllast=$(($wl_numcllast + $wl_numcl)) |
651 | | | fi |
652 | | | fi |
653 | | | |
654 | 6 | simandl | done |
655 | | | wl_numclold=$wl_numcllast |
656 | | | |
657 | 11 | simandl | if [ $wcm_col -eq 0 ] |
658 | 6 | simandl | then |
659 | | | w_bw |
660 | 11 | simandl | else |
661 | 15 | simandl | if [ $wcm_html -eq 1 ] |
662 | | | then |
663 | | | w_colh |
664 | | | else |
665 | | | w_col |
666 | | | fi |
667 | 6 | simandl | fi |
668 | | | |
669 | 13 | simandl | if [ $wcm_html -eq 1 ] |
670 | | | then |
671 | | | [ $wcm_once -eq 1 ] && echo $wl_header || echo $wl_header_refresh |
672 | | | for wl_iface in $wcm_ifc |
673 | | | do |
674 | | | w_iface |
675 | | | done |
676 | | | echo $wl_footer |
677 | | | exit 0 |
678 | | | fi |
679 | | | |
680 | 15 | simandl | #this is main loop and it will be executed forever |
681 | 6 | simandl | while [ 1 ] |
682 | 5 | simandl | do |
683 | 14 | simandl | |
684 | | | # when the number of associated klients has changed we will set for clear screen |
685 | 5 | simandl | if [ $wl_numcllast -ne $wl_numclold ] |
686 | | | then |
687 | | | wl_numclold=$wl_numcllast |
688 | | | wcm_clear=1 |
689 | | | fi |
690 | 14 | simandl | |
691 | | | #if it is set for clear screen we will do it except we produce single report |
692 | | | if [ $wcm_clear -eq 1 -a $wcm_once -eq 0 ] |
693 | 5 | simandl | then |
694 | 14 | simandl | echo -n $wl_clrcmde |
695 | 5 | simandl | wcm_clear=0 |
696 | | | fi |
697 | | | wl_numcllast=0 |
698 | 11 | simandl | |
699 | 14 | simandl | #for cyclic report we are trying to set cursor to the top left screen corner |
700 | | | if [ $wcm_once -eq 0 ] |
701 | | | then |
702 | | | echo -n $wl_tptcmde |
703 | | | fi |
704 | | | |
705 | | | #make report for all desired interfaces |
706 | 13 | simandl | for wl_iface in $wcm_ifc |
707 | | | do |
708 | | | w_iface |
709 | | | done |
710 | | | |
711 | 14 | simandl | #when a single report is needed than we are exiting |
712 | 5 | simandl | if [ $wcm_once -eq 1 ] |
713 | | | then |
714 | | | exit 0 |
715 | | | fi |
716 | | | sleep 1 |
717 | 6 | simandl | done |
718 | 5 | simandl | |
719 | | | exit 0 |
720 | | | |