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