1 | 2 | simandl | #!/bin/bash |
2 | 3 | simandl | # authors : Petr Simandl www.simandl.cz |
3 | 4 | simandl | # : Fyzik |
4 | | | # release date : 6/1/2003 |
5 | 2 | simandl | # name : wifimon |
6 | 4 | simandl | # version : 0.2 beta 2 |
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 | | | wl_header="<html><head><meta HTTP-EQUIV=\"Refresh\" CONTENT=\"1\"><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 | 2 | simandl | wlm_no_managed_or_master=" neni ani Master ani Managed..." |
37 | | | wlm_number_of_clients="Pocet asociovanych klientu : " |
38 | | | #wlm_no_managed_or_master=" is not Master or Managed..." |
39 | | | #wlm_number_of_clients="Number of associated clients : " |
40 | 4 | simandl | |
41 | 2 | simandl | ###################################################################### |
42 | 4 | simandl | w_bw() |
43 | | | { |
44 | | | wlc_ip=$wlc_std |
45 | | | wlc_mac=$wlc_std |
46 | | | wlc_sig=$wlc_std |
47 | | | wlc_bar=$wlc_std |
48 | | | } |
49 | | | ###################################################################### |
50 | 2 | simandl | w_bar() |
51 | | | { |
52 | 4 | simandl | echo -n "${wlc_bar}" |
53 | 2 | simandl | until [ "$wl_cnt" -eq -1 ] |
54 | | | do |
55 | | | printf "=" |
56 | | | wl_cnt=$(($wl_cnt - 1 )) |
57 | | | done |
58 | | | printf " \n" |
59 | 4 | simandl | tput sgr0 |
60 | 2 | simandl | } # w_bar |
61 | | | |
62 | | | ###################################################################### |
63 | | | w_managed() |
64 | | | { echo $wl_iwctxt | awk '{print $1,$3,$4,$5" "}' |
65 | 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 |
66 | | | echo $wl_iwctxt | awk '{print $9,$6,$11" "}' |
67 | 2 | simandl | #echo $wl_iwctxt | awk '{print $27,$28,$29,$31,$32" "}' |
68 | | | #cat $wl_wireless | grep $wl_iface |
69 | | | wl_wtxt=`cat $wl_wireless | grep $wl_iface | awk '{print $3,$4,$5}' | sed 's/\.//g'` |
70 | | | wl_quality=`echo $wl_wtxt | awk '{print $1}'` |
71 | | | wl_signal=`echo $wl_wtxt | awk '{print $2}'` |
72 | | | wl_signal=$(($wl_signal - 256)) |
73 | | | wl_noise=`echo $wl_wtxt | awk '{print $3}'` |
74 | | | wl_noise=$(($wl_noise - 256)) |
75 | 4 | simandl | echo "Quality:${wlc_sig}$wl_quality${wlc_std}/92 Signal level:$wl_signal Noise level:$wl_noise" |
76 | 2 | simandl | wl_cnt=$wl_quality |
77 | | | w_bar |
78 | | | #wl_cnt=$(($wl_cnt + 100)) |
79 | | | #w_bar |
80 | | | echo |
81 | | | } # w_managed |
82 | | | |
83 | | | ###################################################################### |
84 | | | w_master() |
85 | | | { echo $wl_iwctxt | awk '{print $1,$3,$4,$5" "}' |
86 | | | echo $wl_iwctxt | awk '{print $6,$9,$11" "}' |
87 | | | |
88 | | | wl_numcl=`ls $wl_hostap$wl_iface | grep -c 00` |
89 | | | echo $wlm_number_of_clients $wl_numcl |
90 | 3 | simandl | for wl_mac in `ls $wl_hostap$wl_iface | grep 00 ` |
91 | 2 | simandl | do |
92 | | | wl_macparam=`cat $wl_hostap$wl_iface/$wl_mac | grep -E 'last_rx|last_tx'` |
93 | | | wl_cnt=`echo $wl_macparam | awk '{print $5}' | sed 's/signal=//g'` |
94 | 3 | simandl | wl_umac=`echo $wl_mac | tr abcdef ABCDEF` |
95 | | | wl_ipc=`cat $wl_arp | grep $wl_umac | awk '{print $1}'` # IP adresa peeru z arp tabulky |
96 | 4 | simandl | echo -n "${wlc_ip}$wl_ipc${wlc_std} " |
97 | | | echo -n "${wlc_mac}$wl_umac${wlc_std} Signal ${wlc_sig}$wl_cnt${wlc_std} " |
98 | | | echo $wl_macparam | awk '{print $1,$2" "}' |
99 | 2 | simandl | w_bar |
100 | 4 | simandl | done |
101 | 2 | simandl | |
102 | | | echo |
103 | | | } # w_master |
104 | | | |
105 | | | ###################################################################### |
106 | | | w_iface() |
107 | | | { wl_iwctxt=`$wl_iwccmd $wl_iface | grep -v 'Device|Some|Extension' | sed 's/ Nick/_Nick/g'` |
108 | | | wl_mode=`echo $wl_iwctxt | awk '{print $5}' | sed 's/Mode://g'` |
109 | | | if [ "a$wl_mode" = "aManaged" ] |
110 | | | then |
111 | | | w_managed |
112 | | | elif [ "a$wl_mode" = "aMaster" ] |
113 | | | then |
114 | | | w_master |
115 | | | else |
116 | | | echo $wl_iface $wlm_no_managed_or_master |
117 | | | echo |
118 | | | fi |
119 | | | } |
120 | | | |
121 | | | ###################################################################### |
122 | | | ###################################################################### |
123 | | | |
124 | 3 | simandl | case $1 in |
125 | | | -help) |
126 | | | echo Pouziti: wifimon [param] |
127 | | | echo param: |
128 | | | echo -htm cyklicke generovani stranky s 1s obnonovanim |
129 | | | echo -htm1 jedna staticka stranka |
130 | 4 | simandl | echo -col barevny cyklicky vypis na obrazovku |
131 | 3 | simandl | echo bez parametru cyklicky vypis na obrazovku |
132 | 2 | simandl | |
133 | 3 | simandl | ;; |
134 | | | -htm1) |
135 | 4 | simandl | |
136 | | | ;; |
137 | | | -htm1) |
138 | | | echo bez parametru cyklicky vypis na obrazovku |
139 | | | |
140 | | | ;; |
141 | | | -htm1) |
142 | | | w_bw |
143 | 3 | simandl | echo $wl_header_static > $wl_webpage |
144 | | | for wl_iface in `ls $wl_hostap` |
145 | | | do |
146 | | | w_iface >> $wl_webpage |
147 | | | done |
148 | | | echo $wl_footer >> $wl_webpage |
149 | | | ;; |
150 | | | -htm) |
151 | 4 | simandl | w_bw |
152 | 3 | simandl | while [ 1 ] |
153 | | | do |
154 | | | echo $wl_header > $wl_webpage.tmp |
155 | | | for wl_iface in `ls $wl_hostap` |
156 | | | do |
157 | | | w_iface >> $wl_webpage.tmp |
158 | | | done |
159 | | | echo $wl_footer >> $wl_webpage.tmp |
160 | | | cp $wl_webpage.tmp $wl_webpage |
161 | | | sleep 1 |
162 | 2 | simandl | done |
163 | 3 | simandl | ;; |
164 | 4 | simandl | -col) |
165 | | | clear |
166 | | | while [ 1 ] |
167 | | | do |
168 | | | tput cup 0 0 |
169 | | | for wl_iface in `ls $wl_hostap` |
170 | | | do |
171 | | | w_iface |
172 | | | done |
173 | | | sleep 1 |
174 | | | done |
175 | | | ;; |
176 | 3 | simandl | *) |
177 | 4 | simandl | w_bw |
178 | 3 | simandl | clear |
179 | | | while [ 1 ] |
180 | | | do |
181 | | | tput cup 0 0 |
182 | | | for wl_iface in `ls $wl_hostap` |
183 | | | do |
184 | | | w_iface |
185 | | | done |
186 | | | sleep 1 |
187 | | | done |
188 | | | esac |
189 | 2 | simandl | |
190 | | | exit 0 |
191 | | | |
192 | | | |