1 | 2 | simandl | #!/bin/bash |
2 | 3 | simandl | # authors : Petr Simandl www.simandl.cz |
3 | 4 | simandl | # : Fyzik |
4 | 5 | simandl | # release date : 22/1/2003 |
5 | 2 | simandl | # name : wifimon |
6 | 5 | simandl | # version : 0.3 |
7 | 2 | simandl | # description : hostap powered wifi card monitoring |
8 | | | # license : GPL |
9 | | | |
10 | | | wl_iwccmd="/usr/local/sbin/iwconfig" |
11 | 3 | simandl | wl_ifccmd="/sbin/ifconfig" |
12 | | | wl_hnmcmd="/bin/hostname" |
13 | 2 | simandl | wl_hostap="/proc/net/hostap/" |
14 | | | wl_wireless="/proc/net/wireless" |
15 | 3 | simandl | wl_arp="/proc/net/arp" |
16 | 2 | simandl | |
17 | 4 | simandl | wlc_red=`tput setaf 1` |
18 | | | wlc_green=`tput setaf 2` |
19 | | | wlc_brown=`tput setaf 3` |
20 | | | wlc_blue=`tput setaf 4` |
21 | | | wlc_magenta=`tput setaf 5` |
22 | | | wlc_lblue=`tput setaf 6` |
23 | | | wlc_grey=`tput setaf 7` |
24 | | | wlc_std=`tput sgr0` |
25 | | | |
26 | | | wlc_ip=$wlc_lblue # ip address color |
27 | | | wlc_mac=$wlc_magenta # mac address color |
28 | | | wlc_sig=$wlc_red # signal number color |
29 | | | wlc_bar=$wlc_green # signal bar color |
30 | | | |
31 | 3 | simandl | wl_webpage="/tmp/wifimon.htm" |
32 | 5 | simandl | wl_header="<html><head><meta HTTP-EQUIV=\"Refresh\" CONTENT=\"3\"><title>Wifimon @ `$wl_hnmcmd`</title></head><body BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\"><pre>" |
33 | 3 | simandl | wl_header_static="<html><head><title>Wifimon @ `$wl_hnmcmd`</title></head><body BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\"><pre>" |
34 | | | wl_footer="</pre></body></html>" |
35 | | | |
36 | 2 | simandl | wlm_no_managed_or_master=" neni ani Master ani Managed..." |
37 | | | wlm_number_of_clients="Pocet asociovanych klientu : " |
38 | 5 | simandl | wlm_unknown="Nezname parametry nebo neplatne jmeno rozhrani : " |
39 | 2 | simandl | #wlm_no_managed_or_master=" is not Master or Managed..." |
40 | | | #wlm_number_of_clients="Number of associated clients : " |
41 | 4 | simandl | |
42 | 2 | simandl | ###################################################################### |
43 | 4 | simandl | w_bw() |
44 | | | { |
45 | | | wlc_ip=$wlc_std |
46 | | | wlc_mac=$wlc_std |
47 | | | wlc_sig=$wlc_std |
48 | | | wlc_bar=$wlc_std |
49 | | | } |
50 | | | ###################################################################### |
51 | 2 | simandl | w_bar() |
52 | | | { |
53 | 4 | simandl | echo -n "${wlc_bar}" |
54 | 2 | simandl | until [ "$wl_cnt" -eq -1 ] |
55 | | | do |
56 | | | printf "=" |
57 | | | wl_cnt=$(($wl_cnt - 1 )) |
58 | | | done |
59 | | | printf " \n" |
60 | 4 | simandl | tput sgr0 |
61 | 2 | simandl | } # w_bar |
62 | | | |
63 | | | ###################################################################### |
64 | | | w_managed() |
65 | | | { echo $wl_iwctxt | awk '{print $1,$3,$4,$5" "}' |
66 | 3 | simandl | 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 |
67 | | | echo $wl_iwctxt | awk '{print $9,$6,$11" "}' |
68 | 2 | simandl | #echo $wl_iwctxt | awk '{print $27,$28,$29,$31,$32" "}' |
69 | | | #cat $wl_wireless | grep $wl_iface |
70 | | | wl_wtxt=`cat $wl_wireless | grep $wl_iface | awk '{print $3,$4,$5}' | sed 's/\.//g'` |
71 | | | wl_quality=`echo $wl_wtxt | awk '{print $1}'` |
72 | | | wl_signal=`echo $wl_wtxt | awk '{print $2}'` |
73 | | | wl_signal=$(($wl_signal - 256)) |
74 | | | wl_noise=`echo $wl_wtxt | awk '{print $3}'` |
75 | | | wl_noise=$(($wl_noise - 256)) |
76 | 5 | simandl | echo "Quality:${wlc_sig}$wl_quality${wlc_std}/92 Signal level:$wl_signal Noise level:$wl_noise " |
77 | 2 | simandl | wl_cnt=$wl_quality |
78 | | | w_bar |
79 | | | #wl_cnt=$(($wl_cnt + 100)) |
80 | | | #w_bar |
81 | | | echo |
82 | | | } # w_managed |
83 | | | |
84 | | | ###################################################################### |
85 | | | w_master() |
86 | 5 | simandl | { if [ $wcm_oneline -eq 0 ] |
87 | | | then |
88 | | | echo $wl_iwctxt | awk '{print $1,$3,$4,$5" "}' |
89 | | | echo $wl_iwctxt | awk '{print $6,$9,$11" "}' |
90 | | | else |
91 | | | echo $wl_iwctxt | awk '{print $1,$4,$5,$6,$11" "}' | sed 's/ [^": ]*:/ /g' |
92 | | | fi |
93 | 2 | simandl | |
94 | | | wl_numcl=`ls $wl_hostap$wl_iface | grep -c 00` |
95 | | | echo $wlm_number_of_clients $wl_numcl |
96 | 5 | simandl | wl_numcllast=$(($wl_numcllast + $wl_numcl)) |
97 | 3 | simandl | for wl_mac in `ls $wl_hostap$wl_iface | grep 00 ` |
98 | 2 | simandl | do |
99 | | | wl_macparam=`cat $wl_hostap$wl_iface/$wl_mac | grep -E 'last_rx|last_tx'` |
100 | | | wl_cnt=`echo $wl_macparam | awk '{print $5}' | sed 's/signal=//g'` |
101 | 3 | simandl | wl_umac=`echo $wl_mac | tr abcdef ABCDEF` |
102 | | | wl_ipc=`cat $wl_arp | grep $wl_umac | awk '{print $1}'` # IP adresa peeru z arp tabulky |
103 | 5 | simandl | if [ $wcm_oneline -eq 0 ] |
104 | | | then |
105 | | | echo -n "${wlc_ip}$wl_ipc${wlc_std} " |
106 | | | echo -n "${wlc_mac}$wl_umac${wlc_std} Signal ${wlc_sig}$wl_cnt${wlc_std} " |
107 | | | echo $wl_macparam | awk '{print $1,$2" "}' |
108 | | | w_bar |
109 | | | else |
110 | | | #echo -n "${wlc_ip}$wl_ipc${wlc_std} " |
111 | | | echo -n "${wlc_mac}$wl_umac${wlc_std} ${wlc_sig}$wl_cnt${wlc_std} " |
112 | | | #echo -n $wl_macparam | awk '{print $1,$2" "}' |
113 | | | w_bar |
114 | | | fi |
115 | 4 | simandl | done |
116 | 2 | simandl | |
117 | | | echo |
118 | | | } # w_master |
119 | | | |
120 | | | ###################################################################### |
121 | | | w_iface() |
122 | | | { wl_iwctxt=`$wl_iwccmd $wl_iface | grep -v 'Device|Some|Extension' | sed 's/ Nick/_Nick/g'` |
123 | | | wl_mode=`echo $wl_iwctxt | awk '{print $5}' | sed 's/Mode://g'` |
124 | | | if [ "a$wl_mode" = "aManaged" ] |
125 | | | then |
126 | | | w_managed |
127 | | | elif [ "a$wl_mode" = "aMaster" ] |
128 | | | then |
129 | | | w_master |
130 | | | else |
131 | | | echo $wl_iface $wlm_no_managed_or_master |
132 | | | echo |
133 | | | fi |
134 | | | } |
135 | | | |
136 | | | ###################################################################### |
137 | 5 | simandl | w_help() |
138 | | | { |
139 | 3 | simandl | echo Pouziti: wifimon [param] |
140 | | | echo param: |
141 | 5 | simandl | echo -html generovani html stranky |
142 | 4 | simandl | echo -col barevny cyklicky vypis na obrazovku |
143 | 5 | simandl | echo -once vypsani jen jednoho vypisu a pak program skonci |
144 | | | echo -oneline vypsani klientu na jednu linku |
145 | | | echo -wlan0 -wlan1 -wlan2 vypise jen uvedene karty a to v danem poctu a poradi |
146 | 3 | simandl | echo bez parametru cyklicky vypis na obrazovku |
147 | 5 | simandl | exit 0 |
148 | | | } |
149 | | | ###################################################################### |
150 | | | ###################################################################### |
151 | 2 | simandl | |
152 | 5 | simandl | |
153 | | | wl_unknown="" |
154 | | | wl_cnt=1 |
155 | | | wl_numcllast=0 |
156 | | | wl_numclold=0 |
157 | | | wcm_clear=1 |
158 | | | wcm_once=0 |
159 | | | wcm_col=0 |
160 | | | wcm_oneline=0 |
161 | | | wcm_html=0 |
162 | | | wcm_ifc="" |
163 | | | |
164 | | | while [ "a$1" != "a" ] |
165 | | | do |
166 | | | case $1 in |
167 | | | -help) |
168 | | | w_help |
169 | | | ;; |
170 | | | -once) |
171 | | | wcm_once=1 |
172 | | | shift |
173 | | | ;; |
174 | | | -oneline) |
175 | | | wcm_oneline=1 |
176 | | | shift |
177 | | | ;; |
178 | | | -col) |
179 | | | wcm_col=1 |
180 | | | shift |
181 | | | ;; |
182 | | | -html) |
183 | | | wcm_html=1 |
184 | | | shift |
185 | | | ;; |
186 | | | *) |
187 | | | wl_flg=0 |
188 | | | for wl_iface in `ls $wl_hostap` |
189 | | | do |
190 | | | if [ "a-$wl_iface" = "a$1" ] |
191 | | | then |
192 | | | wcm_ifc="$wcm_ifc $wl_iface" |
193 | | | wl_flg=1 |
194 | | | fi |
195 | | | done |
196 | | | if [ $wl_flg -eq 0 ] |
197 | | | then |
198 | | | wl_unknown="$wl_unknown$1 " |
199 | | | fi |
200 | | | shift |
201 | | | esac |
202 | | | done |
203 | | | |
204 | | | if [ "a$wl_unknown" != "a" ] |
205 | | | then |
206 | | | echo "$wlm_unknown $wl_unknown" |
207 | | | w_help |
208 | | | fi |
209 | | | |
210 | | | if [ "a$wcm_ifc" = "a" ] |
211 | | | then |
212 | | | wcm_ifc=`ls $wl_hostap` |
213 | | | fi |
214 | | | |
215 | | | if [ $wcm_col -eq 0 ] |
216 | | | then |
217 | | | w_bw |
218 | | | fi |
219 | | | while [ 1 ] |
220 | | | do |
221 | | | if [ $wl_numcllast -ne $wl_numclold ] |
222 | | | then |
223 | | | wl_numclold=$wl_numcllast |
224 | | | wcm_clear=1 |
225 | | | fi |
226 | | | if [ $wcm_clear -eq 1 ] |
227 | | | then |
228 | | | clear |
229 | | | wcm_clear=0 |
230 | | | fi |
231 | | | tput cup 0 0 |
232 | | | wl_numcllast=0 |
233 | | | if [ $wcm_html -eq 1 ] |
234 | | | then |
235 | | | w_bw |
236 | | | echo $wl_header |
237 | | | for wl_iface in $wcm_ifc |
238 | | | do |
239 | | | w_iface |
240 | | | done |
241 | | | echo $wl_footer |
242 | | | else |
243 | | | for wl_iface in $wcm_ifc |
244 | | | do |
245 | | | w_iface |
246 | | | done |
247 | | | fi |
248 | | | |
249 | | | if [ $wcm_once -eq 1 ] |
250 | | | then |
251 | | | exit 0 |
252 | | | fi |
253 | | | sleep 1 |
254 | | | done |
255 | | | |
256 | | | |
257 | | | |
258 | | | exit 0 |
259 | | | |
260 | | | |
261 | | | case $1 in |
262 | | | -help) |
263 | | | w_help |
264 | 3 | simandl | ;; |
265 | | | -htm1) |
266 | 4 | simandl | |
267 | | | ;; |
268 | 5 | simandl | -1) |
269 | | | w_bw |
270 | | | clear |
271 | | | tput cup 0 0 |
272 | | | for wl_iface in `ls $wl_hostap` |
273 | | | do |
274 | | | w_iface |
275 | | | done |
276 | 4 | simandl | |
277 | | | ;; |
278 | | | -htm1) |
279 | | | w_bw |
280 | 3 | simandl | echo $wl_header_static > $wl_webpage |
281 | | | for wl_iface in `ls $wl_hostap` |
282 | | | do |
283 | | | w_iface >> $wl_webpage |
284 | | | done |
285 | | | echo $wl_footer >> $wl_webpage |
286 | | | ;; |
287 | | | -htm) |
288 | 4 | simandl | w_bw |
289 | 3 | simandl | while [ 1 ] |
290 | | | do |
291 | | | echo $wl_header > $wl_webpage.tmp |
292 | | | for wl_iface in `ls $wl_hostap` |
293 | | | do |
294 | | | w_iface >> $wl_webpage.tmp |
295 | | | done |
296 | | | echo $wl_footer >> $wl_webpage.tmp |
297 | | | cp $wl_webpage.tmp $wl_webpage |
298 | | | sleep 1 |
299 | 2 | simandl | done |
300 | 3 | simandl | ;; |
301 | 4 | simandl | -col) |
302 | | | clear |
303 | | | while [ 1 ] |
304 | | | do |
305 | | | tput cup 0 0 |
306 | | | for wl_iface in `ls $wl_hostap` |
307 | | | do |
308 | | | w_iface |
309 | | | done |
310 | | | sleep 1 |
311 | | | done |
312 | | | ;; |
313 | 3 | simandl | *) |
314 | 4 | simandl | w_bw |
315 | 3 | simandl | clear |
316 | | | while [ 1 ] |
317 | | | do |
318 | | | tput cup 0 0 |
319 | | | for wl_iface in `ls $wl_hostap` |
320 | | | do |
321 | | | w_iface |
322 | | | done |
323 | | | sleep 1 |
324 | | | done |
325 | | | esac |
326 | 2 | simandl | |
327 | | | exit 0 |
328 | | | |
329 | | | |