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