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