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