jablonka.czprosek.czf

wifimon

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

 

Line No. Rev Author Line
12simandl#!/bin/bash
23simandl# authors : Petr Simandl www.simandl.cz
311simandl# : Fyzik, Covex
4# release date : 1/8/2003
52simandl# name : wifimon
6# description : hostap powered wifi card monitoring
7# license : GPL
8 
911simandlwl_version="0.4beta6"
10 
11wl_iwccmd="/usr/local/sbin/iwconfig"
127simandlwl_ifccmd="/sbin/ifconfig"
13wl_hnmcmd="/bin/hostname"
142simandlwl_hostap="/proc/net/hostap/"
15wl_wireless="/proc/net/wireless"
163simandlwl_arp="/proc/net/arp"
1711simandlwl_dhcpcnf="/etc/dhcpd.conf"
182simandl 
194simandl 
207simandlwl_webpage="/tmp/wifimon.htm"
21wl_header="<html><head><meta HTTP-EQUIV=\"Refresh\" CONTENT=\"3\"><title>Wifimon @ `$wl_hnmcmd`</title></head><body BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\"><pre>"
22wl_footer="</pre></body></html>"
23 
24wlm_no_managed_or_master=" neni ani Master ani Managed..."
25wlm_number_of_clients="Pocet asociovanych klientu : "
26wlm_unknown="Nezname parametry nebo neplatne jmeno rozhrani : "
27#wlm_no_managed_or_master=" is not Master or Managed..."
28#wlm_number_of_clients="Number of associated clients : "
29 
3011simandlwlch_signal="="
31wlch_noise="*"
32 
332simandl######################################################################
3411simandlw_col()
3510simandl{
3611simandlwlc_red=`tput setaf 1`
37wlc_green=`tput setaf 2`
38wlc_brown=`tput setaf 3`
39wlc_blue=`tput setaf 4`
40wlc_magenta=`tput setaf 5`
41wlc_lblue=`tput setaf 6`
42wlc_grey=`tput setaf 7`
43wlc_std=`tput sgr0`
44 
45wlc_ip=$wlc_lblue # ip address color
46wlc_mac=$wlc_magenta # mac address color
47wlc_sig=$wlc_red # signal number color
48wlc_bar=$wlc_green # signal bar color
4910simandl}
50######################################################################
514simandlw_bw()
52{
536simandl wlc_ip=""
54 wlc_mac=""
55 wlc_sig=""
56 wlc_bar=""
57 wlc_std=""
584simandl}
59######################################################################
602simandlw_bar()
61{
624simandl echo -n "${wlc_bar}"
6311simandl wl_neg=`expr $wl_cnt \< 0 `
64 if [ "$wl_neg" -eq 1 ]
65 then
66 wl_cnt=$(($wl_cnt * -1 ))
67 wl_bar=$wlch_noise
68 else
69 wl_bar=$wlch_signal
70 fi
712simandl until [ "$wl_cnt" -eq -1 ]
72 do
7311simandl echo -n "$wl_bar"
742simandl wl_cnt=$(($wl_cnt - 1 ))
75 done
76 printf " \n"
776simandl echo -n "${wlc_std}"
7811simandl# tput sgr0
792simandl} # w_bar
80 
81######################################################################
82w_managed()
837simandl{ echo $wl_iwctxt | awk '{print $1,$3,$4,$5" "}'
84 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
85 echo $wl_iwctxt | awk '{print $9,$6,$11" "}'
86 #echo $wl_iwctxt | awk '{print $27,$28,$29,$31,$32" "}'
87 #cat $wl_wireless | grep $wl_iface
88 wl_wtxt=`cat $wl_wireless | grep $wl_iface | awk '{print $3,$4,$5}' | sed 's/\.//g'`
89 wl_quality=`echo $wl_wtxt | awk '{print $1}'`
90 wl_signal=`echo $wl_wtxt | awk '{print $2}'`
912simandl wl_signal=$(($wl_signal - 256))
927simandl wl_noise=`echo $wl_wtxt | awk '{print $3}'`
932simandl wl_noise=$(($wl_noise - 256))
945simandl echo "Quality:${wlc_sig}$wl_quality${wlc_std}/92 Signal level:$wl_signal Noise level:$wl_noise "
952simandl wl_cnt=$wl_quality
96 w_bar
977simandl #wl_cnt=$(($wl_cnt + 100))
98 #w_bar
992simandl echo
100} # w_managed
101 
102######################################################################
103w_master()
1045simandl{ if [ $wcm_oneline -eq 0 ]
105 then
1067simandl echo $wl_iwctxt | awk '{print $1,$3,$4,$5" "}'
107 echo $wl_iwctxt | awk '{print $6,$9,$11" "}'
1085simandl else
1097simandl echo $wl_iwctxt | awk '{print $1,$4,$5,$6,$11" "}' | sed 's/ [^": ]*:/ /g'
1105simandl fi
11111simandl 
1122simandl wl_numcl=`ls $wl_hostap$wl_iface | grep -c 00`
113 echo $wlm_number_of_clients $wl_numcl
1145simandl wl_numcllast=$(($wl_numcllast + $wl_numcl))
1153simandl for wl_mac in `ls $wl_hostap$wl_iface | grep 00 `
1162simandl do
11711simandl wl_macparam=`cat $wl_hostap$wl_iface/$wl_mac | grep -E 'last_rx|last_tx' | sed 's/last_//g'`
118 wl_signal=`echo $wl_macparam | awk '{print $5}' | sed 's/signal=//g'`
119 wl_silence=`echo $wl_macparam | awk '{print $4}' | sed 's/silence=//g'`
120 wl_cnt=$(($wl_signal - $wl_silence))
1218simandl wl_ipc=`cat $wl_arp | grep -i $wl_mac | awk '{print $1}'` # IP adresa peeru z arp tabulky
12211simandl wl_name=`cat $wl_dhcpcnf | grep -i $wl_mac | awk '{print $2}'`
1235simandl if [ $wcm_oneline -eq 0 ]
124 then
12511simandl echo -n "$wl_name "
1265simandl echo -n "${wlc_ip}$wl_ipc${wlc_std} "
12711simandl echo -n "${wlc_mac}$wl_mac${wlc_std} Signal ${wlc_sig}$wl_cnt${wlc_std} "
128 echo $wl_macparam | awk '{print $1,$2" "}'
1295simandl w_bar
130 else
13111simandl echo -n "$wl_name "
132 #echo -n "${wlc_ip}$wl_ipc${wlc_std} "
133 echo -n "${wlc_mac}$wl_mac${wlc_std} ${wlc_sig}$wl_cnt${wlc_std} "
1347simandl #echo -n $wl_macparam | awk '{print $1,$2" "}'
1355simandl w_bar
136 fi
1374simandl done
13811simandl 
139 echo
1402simandl} # w_master
141 
142######################################################################
143w_iface()
14411simandl{ wl_iwctxt=`$wl_iwccmd $wl_iface 2>/dev/null | grep -v 'Device|Some|Extension' | sed 's/ Nick/_Nick/g'`
1457simandl wl_mode=`echo $wl_iwctxt | awk '{print $5}' | sed 's/Mode://g'`
1462simandl if [ "a$wl_mode" = "aManaged" ]
147 then
148 w_managed
1498simandl elif [ "a$wl_mode" = "aAd-Hoc" ]
150 then
151 w_managed
1522simandl elif [ "a$wl_mode" = "aMaster" ]
153 then
154 w_master
155 else
156 echo $wl_iface $wlm_no_managed_or_master
157 echo
158 fi
159}
160 
161######################################################################
16211simandlw_version()
163{
164 echo wifimon $wl_version
165 exit 0
166}
167######################################################################
1685simandlw_help()
169{
1703simandl echo Pouziti: wifimon [param]
171 echo param:
17211simandl echo -v vypise verzi
1735simandl echo -html generovani html stranky
17411simandl echo -col barevny cyklicky vypis na obrazovku
1755simandl echo -once vypsani jen jednoho vypisu a pak program skonci
176 echo -oneline vypsani klientu na jednu linku
177 echo -wlan0 -wlan1 -wlan2 vypise jen uvedene karty a to v danem poctu a poradi
1783simandl echo bez parametru cyklicky vypis na obrazovku
1795simandl exit 0
180}
181######################################################################
182######################################################################
1832simandl 
1845simandlwl_unknown=""
185wl_cnt=1
186wcm_clear=1
187wcm_once=0
18811simandlwcm_col=0
1895simandlwcm_oneline=0
190wcm_html=0
191wcm_ifc=""
192 
1936simandl# parsing input parameters
1945simandlwhile [ "a$1" != "a" ]
195do
196 case $1 in
19711simandl -v)
198 w_version
199 ;;
2005simandl -help)
201 w_help
202 ;;
203 -once)
204 wcm_once=1
205 shift
206 ;;
207 -oneline)
208 wcm_oneline=1
209 shift
210 ;;
21111simandl -col)
212 wcm_col=1
2135simandl shift
214 ;;
215 -html)
216 wcm_html=1
217 shift
218 ;;
219 *)
220 wl_flg=0
221 for wl_iface in `ls $wl_hostap`
222 do
223 if [ "a-$wl_iface" = "a$1" ]
224 then
225 wcm_ifc="$wcm_ifc $wl_iface"
226 wl_flg=1
227 fi
228 done
229 if [ $wl_flg -eq 0 ]
230 then
231 wl_unknown="$wl_unknown$1 "
232 fi
233 shift
234 esac
235done
236 
2376simandl# printing the list of bad parameters (if there are some)
2385simandlif [ "a$wl_unknown" != "a" ]
239then
240 echo "$wlm_unknown $wl_unknown"
241 w_help
242fi
243 
2446simandl# if no interface is selected then all available are choosen
2455simandlif [ "a$wcm_ifc" = "a" ]
246then
247 wcm_ifc=`ls $wl_hostap`
248fi
249 
2506simandl# setting for old and last same value to avoid double clear after start
251wl_numcllast=0
252wl_numclold=0
253for wl_iface in $wcm_ifc
254do
255 wl_numcl=`ls $wl_hostap$wl_iface | grep -c 00`
256 wl_numcllast=$(($wl_numcllast + $wl_numcl))
257done
258wl_numclold=$wl_numcllast
259 
26011simandlif [ $wcm_col -eq 0 ]
2616simandlthen
262 w_bw
26311simandlelse
264 w_col
2656simandlfi
266 
267while [ 1 ]
2685simandl do
269 if [ $wl_numcllast -ne $wl_numclold ]
270 then
271 wl_numclold=$wl_numcllast
272 wcm_clear=1
273 fi
27411simandl if [ $wcm_clear -eq 1 -a $wcm_html -ne 1 ]
2755simandl then
2767simandl clear
2775simandl wcm_clear=0
278 fi
279 wl_numcllast=0
2807simandl if [ $wcm_html -eq 1 ]
2815simandl then
28211simandl w_bw
2837simandl echo $wl_header
284 for wl_iface in $wcm_ifc
285 do
286 w_iface
287 done
288 echo $wl_footer
289 else
290 tput cup 0 0
291 for wl_iface in $wcm_ifc
292 do
293 w_iface
294 done
2955simandl fi
29611simandl 
2975simandl if [ $wcm_once -eq 1 ]
298 then
299 exit 0
300 fi
301 sleep 1
3026simandldone
3035simandl 
304exit 0
305 

Powered by WebSVN 2.2.1