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