1 | 2 | simandl | #!/bin/bash |
2 | 3 | simandl | # authors : Petr Simandl www.simandl.cz |
3 | 11 | simandl | # : Fyzik, Covex |
4 | 13 | simandl | # release date : 14/8/2003 |
5 | 2 | simandl | # name : wifimon |
6 | | | # description : hostap powered wifi card monitoring |
7 | | | # license : GPL |
8 | | | |
9 | 13 | simandl | wl_version="0.4beta8" |
10 | 11 | simandl | |
11 | 13 | simandl | PATH=$PATH:$HOME/bin:/bin:/sbin:/usr/bin:/usr/sbin:usr/local/bin:/usr/local/sbin |
12 | | | |
13 | | | wl_iwccmd=`/usr/bin/which iwconfig` |
14 | 12 | simandl | if [ "$wl_iwccmd x" = " x" ] |
15 | | | then |
16 | | | echo "iwconfig not found" |
17 | | | exit 1 |
18 | | | fi |
19 | 7 | simandl | wl_ifccmd="/sbin/ifconfig" |
20 | | | wl_hnmcmd="/bin/hostname" |
21 | 2 | simandl | wl_hostap="/proc/net/hostap/" |
22 | | | wl_wireless="/proc/net/wireless" |
23 | 3 | simandl | wl_arp="/proc/net/arp" |
24 | 11 | simandl | wl_dhcpcnf="/etc/dhcpd.conf" |
25 | 2 | simandl | |
26 | 4 | simandl | |
27 | 13 | simandl | wl_header_refresh="<html><head><meta HTTP-EQUIV=\"Refresh\" CONTENT=\"3\"><title>Wifimon @ `$wl_hnmcmd`</title></head><body BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\"><pre>" |
28 | | | wl_header="<html><head><title>Wifimon @ `$wl_hnmcmd`</title></head><body BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\"><pre>" |
29 | 7 | simandl | wl_footer="</pre></body></html>" |
30 | | | |
31 | | | wlm_no_managed_or_master=" neni ani Master ani Managed..." |
32 | | | wlm_number_of_clients="Pocet asociovanych klientu : " |
33 | | | wlm_unknown="Nezname parametry nebo neplatne jmeno rozhrani : " |
34 | | | #wlm_no_managed_or_master=" is not Master or Managed..." |
35 | | | #wlm_number_of_clients="Number of associated clients : " |
36 | | | |
37 | 11 | simandl | wlch_signal="=" |
38 | | | wlch_noise="*" |
39 | | | |
40 | 2 | simandl | ###################################################################### |
41 | 11 | simandl | w_col() |
42 | 10 | simandl | { |
43 | 11 | simandl | wlc_red=`tput setaf 1` |
44 | | | wlc_green=`tput setaf 2` |
45 | | | wlc_brown=`tput setaf 3` |
46 | | | wlc_blue=`tput setaf 4` |
47 | | | wlc_magenta=`tput setaf 5` |
48 | | | wlc_lblue=`tput setaf 6` |
49 | | | wlc_grey=`tput setaf 7` |
50 | | | wlc_std=`tput sgr0` |
51 | | | |
52 | | | wlc_ip=$wlc_lblue # ip address color |
53 | | | wlc_mac=$wlc_magenta # mac address color |
54 | | | wlc_sig=$wlc_red # signal number color |
55 | | | wlc_bar=$wlc_green # signal bar color |
56 | 10 | simandl | } |
57 | | | ###################################################################### |
58 | 4 | simandl | w_bw() |
59 | | | { |
60 | 6 | simandl | wlc_ip="" |
61 | | | wlc_mac="" |
62 | | | wlc_sig="" |
63 | | | wlc_bar="" |
64 | | | wlc_std="" |
65 | 4 | simandl | } |
66 | | | ###################################################################### |
67 | 2 | simandl | w_bar() |
68 | | | { |
69 | 4 | simandl | echo -n "${wlc_bar}" |
70 | 11 | simandl | wl_neg=`expr $wl_cnt \< 0 ` |
71 | | | if [ "$wl_neg" -eq 1 ] |
72 | | | then |
73 | | | wl_cnt=$(($wl_cnt * -1 )) |
74 | | | wl_bar=$wlch_noise |
75 | | | else |
76 | | | wl_bar=$wlch_signal |
77 | | | fi |
78 | 2 | simandl | until [ "$wl_cnt" -eq -1 ] |
79 | | | do |
80 | 11 | simandl | echo -n "$wl_bar" |
81 | 2 | simandl | wl_cnt=$(($wl_cnt - 1 )) |
82 | | | done |
83 | | | printf " \n" |
84 | 6 | simandl | echo -n "${wlc_std}" |
85 | 11 | simandl | # tput sgr0 |
86 | 2 | simandl | } # w_bar |
87 | | | |
88 | | | ###################################################################### |
89 | 13 | simandl | w_pkts() |
90 | | | { |
91 | | | wl_macpkts=`cat $wl_hostap$wl_iface/$wl_mac | grep -E 'rx\[|tx\[' | sed 's/=/ /g'` |
92 | | | wl_nt1=`echo $wl_macpkts | awk '{print $2}'` |
93 | | | wl_nt2=`echo $wl_macpkts | awk '{print $4}'` |
94 | | | wl_nt5=`echo $wl_macpkts | awk '{print $6}'` |
95 | | | wl_nt11=`echo $wl_macpkts | awk '{print $8}'` |
96 | | | wl_nr1=`echo $wl_macpkts | awk '{print $10}'` |
97 | | | wl_nr2=`echo $wl_macpkts | awk '{print $12}'` |
98 | | | wl_nr5=`echo $wl_macpkts | awk '{print $14}'` |
99 | | | wl_nr11=`echo $wl_macpkts | awk '{print $16}'` |
100 | | | |
101 | | | if [ $wcm_ppkts -eq 1 ] |
102 | | | then |
103 | | | wl_pksize=$((98)) |
104 | | | wl_nt=$(($wl_nt1 + $wl_nt2 + wl_nt5 + wl_nt11)) |
105 | | | if [ "$wl_nt1" -eq 0 ] |
106 | | | then |
107 | | | wl_nt1n="00" |
108 | | | else |
109 | | | wl_nt1n=$(($wl_pksize * $wl_nt1 / $wl_nt + 1)) |
110 | | | [ "$wl_nt1n" -lt 10 ] && wl_nt1n="0"$wl_nt1n |
111 | | | fi |
112 | | | if [ "$wl_nt2" -eq 0 ] |
113 | | | then |
114 | | | wl_nt2n="00" |
115 | | | else |
116 | | | wl_nt2n=$(($wl_pksize * $wl_nt2 / $wl_nt + 1)) |
117 | | | [ "$wl_nt2n" -lt 10 ] && wl_nt2n="0"$wl_nt2n |
118 | | | fi |
119 | | | if [ "$wl_nt5" -eq 0 ] |
120 | | | then |
121 | | | wl_nt5n="00" |
122 | | | else |
123 | | | wl_nt5n=$(($wl_pksize * $wl_nt5 / $wl_nt + 1)) |
124 | | | [ "$wl_nt5n" -lt 10 ] && wl_nt5n="0"$wl_nt5n |
125 | | | fi |
126 | | | if [ "$wl_nt11" -eq 0 ] |
127 | | | then |
128 | | | wl_nt11n="00" |
129 | | | else |
130 | | | wl_nt11n=$(($wl_pksize * $wl_nt11 / $wl_nt + 1)) |
131 | | | [ "$wl_nt11n" -lt 10 ] && wl_nt11n="0"$wl_nt11n |
132 | | | fi |
133 | | | wl_nr=$((1 + $wl_nr1 + $wl_nr2 + wl_nr5 + wl_nr11)) |
134 | | | if [ "$wl_nr1" -eq 0 ] |
135 | | | then |
136 | | | wl_nr1n="00" |
137 | | | else |
138 | | | wl_nr1n=$(($wl_pksize * $wl_nr1 / $wl_nr + 1)) |
139 | | | [ "$wl_nr1n" -lt 10 ] && wl_nr1n="0"$wl_nr1n |
140 | | | fi |
141 | | | if [ "$wl_nr2" -eq 0 ] |
142 | | | then |
143 | | | wl_nr2n="00" |
144 | | | else |
145 | | | wl_nr2n=$(($wl_pksize * $wl_nr2 / $wl_nr + 1)) |
146 | | | [ "$wl_nr2n" -lt 10 ] && wl_nr2n="0"$wl_nr2n |
147 | | | fi |
148 | | | if [ "$wl_nr5" -eq 0 ] |
149 | | | then |
150 | | | wl_nr5n="00" |
151 | | | else |
152 | | | wl_nr5n=$(($wl_pksize * $wl_nr5 / $wl_nr + 1)) |
153 | | | [ "$wl_nr5n" -lt 10 ] && wl_nr5n="0"$wl_nr5n |
154 | | | fi |
155 | | | if [ "$wl_nr11" -eq 0 ] |
156 | | | then |
157 | | | wl_nr11n="00" |
158 | | | else |
159 | | | wl_nr11n=$(($wl_pksize * $wl_nr11 / $wl_nr + 1)) |
160 | | | [ "$wl_nr11n" -lt 10 ] && wl_nr11n="0"$wl_nr11n |
161 | | | fi |
162 | | | echo -n "Tx" $wl_nt1n $wl_nt2n $wl_nt5n $wl_nt11n "Rx" $wl_nr1n $wl_nr2n $wl_nr5n $wl_nr11n "" |
163 | | | fi |
164 | | | |
165 | | | [ $wcm_pkts -eq 1 ] && echo -n "Tx" $wl_nt1 $wl_nt2 $wl_nt5 $wl_nt11 "Rx" $wl_nr1 $wl_nr2 $wl_nr5 $wl_nr11 "" |
166 | | | |
167 | | | } # w_pkts |
168 | | | ###################################################################### |
169 | 2 | simandl | w_managed() |
170 | 7 | simandl | { echo $wl_iwctxt | awk '{print $1,$3,$4,$5" "}' |
171 | | | echo -n `$wl_ifccmd $wl_iface | grep -E "inet addr|inet adr" | awk '{print $2" "}' | sed s/ad*r://g`" " # IP adresa mastera z ifconfig |
172 | | | echo $wl_iwctxt | awk '{print $9,$6,$11" "}' |
173 | | | wl_wtxt=`cat $wl_wireless | grep $wl_iface | awk '{print $3,$4,$5}' | sed 's/\.//g'` |
174 | | | wl_quality=`echo $wl_wtxt | awk '{print $1}'` |
175 | | | wl_signal=`echo $wl_wtxt | awk '{print $2}'` |
176 | 2 | simandl | wl_signal=$(($wl_signal - 256)) |
177 | 7 | simandl | wl_noise=`echo $wl_wtxt | awk '{print $3}'` |
178 | 2 | simandl | wl_noise=$(($wl_noise - 256)) |
179 | 5 | simandl | echo "Quality:${wlc_sig}$wl_quality${wlc_std}/92 Signal level:$wl_signal Noise level:$wl_noise " |
180 | 2 | simandl | wl_cnt=$wl_quality |
181 | | | w_bar |
182 | | | echo |
183 | | | } # w_managed |
184 | | | |
185 | | | ###################################################################### |
186 | | | w_master() |
187 | 5 | simandl | { if [ $wcm_oneline -eq 0 ] |
188 | | | then |
189 | 7 | simandl | echo $wl_iwctxt | awk '{print $1,$3,$4,$5" "}' |
190 | | | echo $wl_iwctxt | awk '{print $6,$9,$11" "}' |
191 | 5 | simandl | else |
192 | 7 | simandl | echo $wl_iwctxt | awk '{print $1,$4,$5,$6,$11" "}' | sed 's/ [^": ]*:/ /g' |
193 | 5 | simandl | fi |
194 | 11 | simandl | |
195 | 2 | simandl | wl_numcl=`ls $wl_hostap$wl_iface | grep -c 00` |
196 | | | echo $wlm_number_of_clients $wl_numcl |
197 | 13 | simandl | |
198 | 5 | simandl | wl_numcllast=$(($wl_numcllast + $wl_numcl)) |
199 | 13 | simandl | |
200 | 3 | simandl | for wl_mac in `ls $wl_hostap$wl_iface | grep 00 ` |
201 | 2 | simandl | do |
202 | 11 | simandl | wl_macparam=`cat $wl_hostap$wl_iface/$wl_mac | grep -E 'last_rx|last_tx' | sed 's/last_//g'` |
203 | | | wl_signal=`echo $wl_macparam | awk '{print $5}' | sed 's/signal=//g'` |
204 | | | wl_silence=`echo $wl_macparam | awk '{print $4}' | sed 's/silence=//g'` |
205 | | | wl_cnt=$(($wl_signal - $wl_silence)) |
206 | 8 | simandl | wl_ipc=`cat $wl_arp | grep -i $wl_mac | awk '{print $1}'` # IP adresa peeru z arp tabulky |
207 | 11 | simandl | wl_name=`cat $wl_dhcpcnf | grep -i $wl_mac | awk '{print $2}'` |
208 | 13 | simandl | |
209 | | | if [ $wcm_ppkts -eq 1 ] || [ $wcm_pkts -eq 1 ] |
210 | | | then |
211 | | | w_pkts |
212 | | | fi |
213 | | | |
214 | 5 | simandl | if [ $wcm_oneline -eq 0 ] |
215 | | | then |
216 | 11 | simandl | echo -n "$wl_name " |
217 | 5 | simandl | echo -n "${wlc_ip}$wl_ipc${wlc_std} " |
218 | 11 | simandl | echo -n "${wlc_mac}$wl_mac${wlc_std} Signal ${wlc_sig}$wl_cnt${wlc_std} " |
219 | | | echo $wl_macparam | awk '{print $1,$2" "}' |
220 | 5 | simandl | w_bar |
221 | | | else |
222 | 11 | simandl | echo -n "$wl_name " |
223 | | | echo -n "${wlc_mac}$wl_mac${wlc_std} ${wlc_sig}$wl_cnt${wlc_std} " |
224 | 5 | simandl | w_bar |
225 | | | fi |
226 | 4 | simandl | done |
227 | 11 | simandl | |
228 | | | echo |
229 | 2 | simandl | } # w_master |
230 | | | |
231 | | | ###################################################################### |
232 | | | w_iface() |
233 | 13 | simandl | { wl_iwctxt=`$wl_iwccmd $wl_iface 2>/dev/null | grep -v 'Device|Some|Extension' | sed 's/ Nick/_Nick/'` |
234 | 7 | simandl | wl_mode=`echo $wl_iwctxt | awk '{print $5}' | sed 's/Mode://g'` |
235 | 2 | simandl | if [ "a$wl_mode" = "aManaged" ] |
236 | | | then |
237 | | | w_managed |
238 | 8 | simandl | elif [ "a$wl_mode" = "aAd-Hoc" ] |
239 | | | then |
240 | | | w_managed |
241 | 2 | simandl | elif [ "a$wl_mode" = "aMaster" ] |
242 | | | then |
243 | | | w_master |
244 | | | else |
245 | | | echo $wl_iface $wlm_no_managed_or_master |
246 | | | echo |
247 | | | fi |
248 | | | } |
249 | | | |
250 | | | ###################################################################### |
251 | 11 | simandl | w_version() |
252 | | | { |
253 | | | echo wifimon $wl_version |
254 | | | exit 0 |
255 | | | } |
256 | | | ###################################################################### |
257 | 5 | simandl | w_help() |
258 | | | { |
259 | 3 | simandl | echo Pouziti: wifimon [param] |
260 | | | echo param: |
261 | 11 | simandl | echo -v vypise verzi |
262 | 5 | simandl | echo -html generovani html stranky |
263 | 13 | simandl | echo -col barevny vypis na obrazovku |
264 | 5 | simandl | echo -once vypsani jen jednoho vypisu a pak program skonci |
265 | | | echo -oneline vypsani klientu na jednu linku |
266 | 13 | simandl | echo -ppkts vypsani procentniho pomeru 1M, 2M, 5.5M a 11M paketu pro jednotlive klienty |
267 | | | echo -pkts vypsani poctu 1M, 2M, 5.5M a 11M paketu pro jednotlive klienty |
268 | 5 | simandl | echo -wlan0 -wlan1 -wlan2 vypise jen uvedene karty a to v danem poctu a poradi |
269 | 3 | simandl | echo bez parametru cyklicky vypis na obrazovku |
270 | 5 | simandl | exit 0 |
271 | | | } |
272 | | | ###################################################################### |
273 | | | ###################################################################### |
274 | 2 | simandl | |
275 | 5 | simandl | wl_unknown="" |
276 | | | wl_cnt=1 |
277 | | | wcm_clear=1 |
278 | | | wcm_once=0 |
279 | 11 | simandl | wcm_col=0 |
280 | 5 | simandl | wcm_oneline=0 |
281 | | | wcm_html=0 |
282 | 13 | simandl | wcm_ppkts=0 |
283 | | | wcm_pkts=0 |
284 | 5 | simandl | wcm_ifc="" |
285 | | | |
286 | 6 | simandl | # parsing input parameters |
287 | 5 | simandl | while [ "a$1" != "a" ] |
288 | | | do |
289 | | | case $1 in |
290 | 11 | simandl | -v) |
291 | | | w_version |
292 | | | ;; |
293 | 5 | simandl | -help) |
294 | | | w_help |
295 | | | ;; |
296 | | | -once) |
297 | | | wcm_once=1 |
298 | | | shift |
299 | | | ;; |
300 | | | -oneline) |
301 | | | wcm_oneline=1 |
302 | | | shift |
303 | | | ;; |
304 | 11 | simandl | -col) |
305 | | | wcm_col=1 |
306 | 5 | simandl | shift |
307 | | | ;; |
308 | | | -html) |
309 | | | wcm_html=1 |
310 | | | shift |
311 | | | ;; |
312 | 13 | simandl | -ppkts) |
313 | | | wcm_ppkts=1 |
314 | | | shift |
315 | | | ;; |
316 | | | -pkts) |
317 | | | wcm_pkts=1 |
318 | | | shift |
319 | | | ;; |
320 | 5 | simandl | *) |
321 | | | wl_flg=0 |
322 | | | for wl_iface in `ls $wl_hostap` |
323 | | | do |
324 | | | if [ "a-$wl_iface" = "a$1" ] |
325 | | | then |
326 | | | wcm_ifc="$wcm_ifc $wl_iface" |
327 | | | wl_flg=1 |
328 | | | fi |
329 | | | done |
330 | | | if [ $wl_flg -eq 0 ] |
331 | | | then |
332 | | | wl_unknown="$wl_unknown$1 " |
333 | | | fi |
334 | | | shift |
335 | | | esac |
336 | | | done |
337 | | | |
338 | 6 | simandl | # printing the list of bad parameters (if there are some) |
339 | 5 | simandl | if [ "a$wl_unknown" != "a" ] |
340 | | | then |
341 | | | echo "$wlm_unknown $wl_unknown" |
342 | | | w_help |
343 | | | fi |
344 | | | |
345 | 6 | simandl | # if no interface is selected then all available are choosen |
346 | 5 | simandl | if [ "a$wcm_ifc" = "a" ] |
347 | | | then |
348 | | | wcm_ifc=`ls $wl_hostap` |
349 | | | fi |
350 | | | |
351 | 6 | simandl | # setting for old and last same value to avoid double clear after start |
352 | | | wl_numcllast=0 |
353 | | | wl_numclold=0 |
354 | | | for wl_iface in $wcm_ifc |
355 | | | do |
356 | | | wl_numcl=`ls $wl_hostap$wl_iface | grep -c 00` |
357 | | | wl_numcllast=$(($wl_numcllast + $wl_numcl)) |
358 | | | done |
359 | | | wl_numclold=$wl_numcllast |
360 | | | |
361 | 11 | simandl | if [ $wcm_col -eq 0 ] |
362 | 6 | simandl | then |
363 | | | w_bw |
364 | 11 | simandl | else |
365 | | | w_col |
366 | 6 | simandl | fi |
367 | | | |
368 | 13 | simandl | if [ $wcm_html -eq 1 ] |
369 | | | then |
370 | | | w_bw |
371 | | | [ $wcm_once -eq 1 ] && echo $wl_header || echo $wl_header_refresh |
372 | | | for wl_iface in $wcm_ifc |
373 | | | do |
374 | | | w_iface |
375 | | | done |
376 | | | echo $wl_footer |
377 | | | exit 0 |
378 | | | fi |
379 | | | |
380 | 6 | simandl | while [ 1 ] |
381 | 5 | simandl | do |
382 | | | if [ $wl_numcllast -ne $wl_numclold ] |
383 | | | then |
384 | | | wl_numclold=$wl_numcllast |
385 | | | wcm_clear=1 |
386 | | | fi |
387 | 11 | simandl | if [ $wcm_clear -eq 1 -a $wcm_html -ne 1 ] |
388 | 5 | simandl | then |
389 | 7 | simandl | clear |
390 | 5 | simandl | wcm_clear=0 |
391 | | | fi |
392 | | | wl_numcllast=0 |
393 | 11 | simandl | |
394 | 13 | simandl | [ -e /usr/bin/tput ] && tput cup 0 0 || clear |
395 | | | for wl_iface in $wcm_ifc |
396 | | | do |
397 | | | w_iface |
398 | | | done |
399 | | | |
400 | 5 | simandl | if [ $wcm_once -eq 1 ] |
401 | | | then |
402 | | | exit 0 |
403 | | | fi |
404 | | | sleep 1 |
405 | 6 | simandl | done |
406 | 5 | simandl | |
407 | | | exit 0 |
408 | | | |