jablonka.czprosek.czf

wifimon

Subversion Repositories:
[/] [trunk/] [wifimon] - Blame information for rev 10

 

Line No. Rev Author Line
12simandl#!/bin/bash
23simandl# authors : Petr Simandl www.simandl.cz
310simandl# : Fyzik, Tydyt
4# release date : 9/3/2003
52simandl# name : wifimon
610simandl# version : 0.4beta4
72simandl# description : hostap powered wifi card monitoring
8# license : GPL
9 
1010simandl# Upozorneni: pred instalaci programu doporucuji skontrolaovat nasledujici nasledujici cesty !!!
11#wl_iwccmd="/usr/sbin/iwconfig"
12wl_iwccmd="/sbin/iwconfig"
137simandlwl_ifccmd="/sbin/ifconfig"
14wl_hnmcmd="/bin/hostname"
152simandlwl_hostap="/proc/net/hostap/"
16wl_wireless="/proc/net/wireless"
173simandlwl_arp="/proc/net/arp"
1810simandlwl_dhcp_s="/etc/dhcpd.conf"
19wl_dhcp_d="/var/lib/dhcp/dhcpd.leases"
202simandl 
2110simandlwlc_red=`tput setaf 1` # ruda (Red)
22wlc_green=`tput setaf 2` # zelena (Lime)
23wlc_brown=`tput setaf 3` # zluta (Yellow)
24wlc_blue=`tput setaf 4` # modra (Blue)
25wlc_magenta=`tput setaf 5` # fialova (Fuchsia)
26wlc_lblue=`tput setaf 6` # svetle modra (Aqua)
27wlc_grey=`tput setaf 7` # bila (White)
284simandlwlc_std=`tput sgr0`
29 
30wlc_ip=$wlc_lblue # ip address color
31wlc_mac=$wlc_magenta # mac address color
3210simandlwlc_name=$wlc_brown # host name color
334simandlwlc_sig=$wlc_red # signal number color
34wlc_bar=$wlc_green # signal bar color
357simandl 
3610simandlwlh_ip="Blue" # ip address color html
37wlh_mac="Fuchsia" # mac address color html
38wlh_name="Olive" # Host name color html
39wlh_sig="Red" # signal number color html
40wlh_bar="Lime" # signal bar color html
41 
42 
437simandlwl_webpage="/tmp/wifimon.htm"
44wl_header="<html><head><meta HTTP-EQUIV=\"Refresh\" CONTENT=\"3\"><title>Wifimon @ `$wl_hnmcmd`</title></head><body BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\"><pre>"
4510simandlwl_header_static="<html><head><title>Wifimon @ `$wl_hnmcmd`</title></head><body BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\"><pre>"
467simandlwl_footer="</pre></body></html>"
47 
48wlm_no_managed_or_master=" neni ani Master ani Managed..."
49wlm_number_of_clients="Pocet asociovanych klientu : "
50wlm_unknown="Nezname parametry nebo neplatne jmeno rozhrani : "
5110simandlwlm_number_of_wds="Pocet asociovanych WDS spoju : "
527simandl#wlm_no_managed_or_master=" is not Master or Managed..."
53#wlm_number_of_clients="Number of associated clients : "
54 
552simandl######################################################################
5610simandlw_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######################################################################
664simandlw_bw()
67{
686simandl wlc_ip=""
69 wlc_mac=""
7010simandl wlc_name=""
716simandl wlc_sig=""
72 wlc_bar=""
73 wlc_std=""
744simandl}
75######################################################################
762simandlw_bar()
77{
784simandl echo -n "${wlc_bar}"
792simandl until [ "$wl_cnt" -eq -1 ]
80 do
817simandl printf "="
822simandl wl_cnt=$(($wl_cnt - 1 ))
83 done
84 printf " \n"
856simandl echo -n "${wlc_std}"
862simandl} # w_bar
87 
88######################################################################
89w_managed()
907simandl{ 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}'`
982simandl wl_signal=$(($wl_signal - 256))
997simandl wl_noise=`echo $wl_wtxt | awk '{print $3}'`
1002simandl wl_noise=$(($wl_noise - 256))
1015simandl echo "Quality:${wlc_sig}$wl_quality${wlc_std}/92 Signal level:$wl_signal Noise level:$wl_noise "
1022simandl wl_cnt=$wl_quality
103 w_bar
1047simandl #wl_cnt=$(($wl_cnt + 100))
105 #w_bar
1062simandl echo
107} # w_managed
108 
109######################################################################
110w_master()
1115simandl{ if [ $wcm_oneline -eq 0 ]
112 then
1137simandl echo $wl_iwctxt | awk '{print $1,$3,$4,$5" "}'
114 echo $wl_iwctxt | awk '{print $6,$9,$11" "}'
1155simandl else
1167simandl echo $wl_iwctxt | awk '{print $1,$4,$5,$6,$11" "}' | sed 's/ [^": ]*:/ /g'
1175simandl fi
11810simandl 
1192simandl wl_numcl=`ls $wl_hostap$wl_iface | grep -c 00`
120 echo $wlm_number_of_clients $wl_numcl
1215simandl wl_numcllast=$(($wl_numcllast + $wl_numcl))
1223simandl for wl_mac in `ls $wl_hostap$wl_iface | grep 00 `
1232simandl do
12410simandl wl_macparam=`cat $wl_hostap$wl_iface/$wl_mac | grep -E 'last_rx|last_tx'`
1257simandl wl_cnt=`echo $wl_macparam | awk '{print $5}' | sed 's/signal=//g'`
1268simandl wl_ipc=`cat $wl_arp | grep -i $wl_mac | awk '{print $1}'` # IP adresa peeru z arp tabulky
12710simandl 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
1415simandl if [ $wcm_oneline -eq 0 ]
142 then
14310simandl echo -n "${wlc_mac}$wl_mac${wlc_std} Signal:${wlc_sig}$wl_cnt${wlc_std} "
1445simandl echo -n "${wlc_ip}$wl_ipc${wlc_std} "
14510simandl echo -n "${wlc_name}$wl_name${wlc_std} "
146 echo $wl_macparam | awk '{print $1,$2" "}'
1475simandl w_bar
148 else
14910simandl 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} "
1537simandl #echo -n $wl_macparam | awk '{print $1,$2" "}'
1545simandl w_bar
155 fi
1564simandl done
15710simandl echo -n " "
158 echo
1592simandl} # w_master
160 
161######################################################################
16210simandlw_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######################################################################
1722simandlw_iface()
17310simandl{ wl_iwctxt=`$wl_iwccmd $wl_iface | grep -v 'Device|Some|Extension' | sed 's/ Nick/_Nick/g'`
1747simandl wl_mode=`echo $wl_iwctxt | awk '{print $5}' | sed 's/Mode://g'`
1752simandl if [ "a$wl_mode" = "aManaged" ]
176 then
177 w_managed
1788simandl elif [ "a$wl_mode" = "aAd-Hoc" ]
179 then
180 w_managed
1812simandl 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######################################################################
1915simandlw_help()
192{
1933simandl echo Pouziti: wifimon [param]
194 echo param:
1955simandl echo -html generovani html stranky
19610simandl echo -mono monochroni vypis na obrazovku
1975simandl 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
2003simandl echo bez parametru cyklicky vypis na obrazovku
2015simandl exit 0
202}
203######################################################################
204######################################################################
2052simandl 
2065simandlwl_unknown=""
207wl_cnt=1
208wcm_clear=1
209wcm_once=0
21010simandlwcm_mono=0
2115simandlwcm_oneline=0
212wcm_html=0
213wcm_ifc=""
214 
2156simandl# parsing input parameters
2165simandlwhile [ "a$1" != "a" ]
217do
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 ;;
23010simandl -mono)
231 wcm_mono=1
2325simandl 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
254done
255 
2566simandl# printing the list of bad parameters (if there are some)
2575simandlif [ "a$wl_unknown" != "a" ]
258then
259 echo "$wlm_unknown $wl_unknown"
260 w_help
261fi
262 
2636simandl# if no interface is selected then all available are choosen
2645simandlif [ "a$wcm_ifc" = "a" ]
265then
266 wcm_ifc=`ls $wl_hostap`
267fi
268 
2696simandl# setting for old and last same value to avoid double clear after start
270wl_numcllast=0
271wl_numclold=0
272for wl_iface in $wcm_ifc
273do
274 wl_numcl=`ls $wl_hostap$wl_iface | grep -c 00`
275 wl_numcllast=$(($wl_numcllast + $wl_numcl))
276done
277wl_numclold=$wl_numcllast
278 
27910simandlif [ $wcm_html -eq 1 ]
2806simandlthen
28110simandl w_html
282fi
283 
284if [ $wcm_mono -eq 1 ]
285then
2866simandl w_bw
287fi
288 
289while [ 1 ]
2905simandl do
291 if [ $wl_numcllast -ne $wl_numclold ]
292 then
293 wl_numclold=$wl_numcllast
294 wcm_clear=1
295 fi
29610simandl if [ $wcm_clear -eq 1 ]
2975simandl then
2987simandl clear
2995simandl wcm_clear=0
300 fi
301 wl_numcllast=0
3027simandl if [ $wcm_html -eq 1 ]
3035simandl then
3047simandl echo $wl_header
305 for wl_iface in $wcm_ifc
306 do
307 w_iface
30810simandl w_wds
3097simandl done
310 echo $wl_footer
311 else
312 tput cup 0 0
313 for wl_iface in $wcm_ifc
314 do
315 w_iface
31610simandl w_wds
3177simandl done
3185simandl fi
319 if [ $wcm_once -eq 1 ]
320 then
321 exit 0
322 fi
323 sleep 1
3246simandldone
3255simandl 
326exit 0
327 
32810simandl 

Powered by WebSVN 2.2.1