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