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