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