jablonka.czprosek.czf

wifimon

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

 

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 
912simandlwl_version="0.4beta7"
1011simandl 
1112simandlwl_iwccmd=`which iwconfig`
12if [ "$wl_iwccmd x" = " x" ]
13 then
14 echo "iwconfig not found"
15 exit 1
16fi
177simandlwl_ifccmd="/sbin/ifconfig"
18wl_hnmcmd="/bin/hostname"
192simandlwl_hostap="/proc/net/hostap/"
20wl_wireless="/proc/net/wireless"
213simandlwl_arp="/proc/net/arp"
2211simandlwl_dhcpcnf="/etc/dhcpd.conf"
232simandl 
244simandl 
257simandlwl_webpage="/tmp/wifimon.htm"
26wl_header="<html><head><meta HTTP-EQUIV=\"Refresh\" CONTENT=\"3\"><title>Wifimon @ `$wl_hnmcmd`</title></head><body BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\"><pre>"
27wl_footer="</pre></body></html>"
28 
29wlm_no_managed_or_master=" neni ani Master ani Managed..."
30wlm_number_of_clients="Pocet asociovanych klientu : "
31wlm_unknown="Nezname parametry nebo neplatne jmeno rozhrani : "
32#wlm_no_managed_or_master=" is not Master or Managed..."
33#wlm_number_of_clients="Number of associated clients : "
34 
3512simandl 
3611simandlwlch_signal="="
37wlch_noise="*"
38 
392simandl######################################################################
4011simandlw_col()
4110simandl{
4211simandlwlc_red=`tput setaf 1`
43wlc_green=`tput setaf 2`
44wlc_brown=`tput setaf 3`
45wlc_blue=`tput setaf 4`
46wlc_magenta=`tput setaf 5`
47wlc_lblue=`tput setaf 6`
48wlc_grey=`tput setaf 7`
49wlc_std=`tput sgr0`
50 
51wlc_ip=$wlc_lblue # ip address color
52wlc_mac=$wlc_magenta # mac address color
53wlc_sig=$wlc_red # signal number color
54wlc_bar=$wlc_green # signal bar color
5510simandl}
56######################################################################
574simandlw_bw()
58{
596simandl wlc_ip=""
60 wlc_mac=""
61 wlc_sig=""
62 wlc_bar=""
63 wlc_std=""
644simandl}
65######################################################################
662simandlw_bar()
67{
684simandl echo -n "${wlc_bar}"
6911simandl wl_neg=`expr $wl_cnt \< 0 `
70 if [ "$wl_neg" -eq 1 ]
71 then
72 wl_cnt=$(($wl_cnt * -1 ))
73 wl_bar=$wlch_noise
74 else
75 wl_bar=$wlch_signal
76 fi
772simandl until [ "$wl_cnt" -eq -1 ]
78 do
7911simandl echo -n "$wl_bar"
802simandl wl_cnt=$(($wl_cnt - 1 ))
81 done
82 printf " \n"
836simandl echo -n "${wlc_std}"
8411simandl# tput sgr0
852simandl} # w_bar
86 
87######################################################################
88w_managed()
897simandl{ echo $wl_iwctxt | awk '{print $1,$3,$4,$5" "}'
90 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
91 echo $wl_iwctxt | awk '{print $9,$6,$11" "}'
92 #echo $wl_iwctxt | awk '{print $27,$28,$29,$31,$32" "}'
93 #cat $wl_wireless | grep $wl_iface
94 wl_wtxt=`cat $wl_wireless | grep $wl_iface | awk '{print $3,$4,$5}' | sed 's/\.//g'`
95 wl_quality=`echo $wl_wtxt | awk '{print $1}'`
96 wl_signal=`echo $wl_wtxt | awk '{print $2}'`
972simandl wl_signal=$(($wl_signal - 256))
987simandl wl_noise=`echo $wl_wtxt | awk '{print $3}'`
992simandl wl_noise=$(($wl_noise - 256))
1005simandl echo "Quality:${wlc_sig}$wl_quality${wlc_std}/92 Signal level:$wl_signal Noise level:$wl_noise "
1012simandl wl_cnt=$wl_quality
102 w_bar
1037simandl #wl_cnt=$(($wl_cnt + 100))
104 #w_bar
1052simandl echo
106} # w_managed
107 
108######################################################################
109w_master()
1105simandl{ if [ $wcm_oneline -eq 0 ]
111 then
1127simandl echo $wl_iwctxt | awk '{print $1,$3,$4,$5" "}'
113 echo $wl_iwctxt | awk '{print $6,$9,$11" "}'
1145simandl else
1157simandl echo $wl_iwctxt | awk '{print $1,$4,$5,$6,$11" "}' | sed 's/ [^": ]*:/ /g'
1165simandl fi
11711simandl 
1182simandl wl_numcl=`ls $wl_hostap$wl_iface | grep -c 00`
119 echo $wlm_number_of_clients $wl_numcl
1205simandl wl_numcllast=$(($wl_numcllast + $wl_numcl))
1213simandl for wl_mac in `ls $wl_hostap$wl_iface | grep 00 `
1222simandl do
12311simandl wl_macparam=`cat $wl_hostap$wl_iface/$wl_mac | grep -E 'last_rx|last_tx' | sed 's/last_//g'`
124 wl_signal=`echo $wl_macparam | awk '{print $5}' | sed 's/signal=//g'`
125 wl_silence=`echo $wl_macparam | awk '{print $4}' | sed 's/silence=//g'`
126 wl_cnt=$(($wl_signal - $wl_silence))
1278simandl wl_ipc=`cat $wl_arp | grep -i $wl_mac | awk '{print $1}'` # IP adresa peeru z arp tabulky
12811simandl wl_name=`cat $wl_dhcpcnf | grep -i $wl_mac | awk '{print $2}'`
1295simandl if [ $wcm_oneline -eq 0 ]
130 then
13111simandl echo -n "$wl_name "
1325simandl echo -n "${wlc_ip}$wl_ipc${wlc_std} "
13311simandl echo -n "${wlc_mac}$wl_mac${wlc_std} Signal ${wlc_sig}$wl_cnt${wlc_std} "
134 echo $wl_macparam | awk '{print $1,$2" "}'
1355simandl w_bar
136 else
13711simandl echo -n "$wl_name "
138 #echo -n "${wlc_ip}$wl_ipc${wlc_std} "
139 echo -n "${wlc_mac}$wl_mac${wlc_std} ${wlc_sig}$wl_cnt${wlc_std} "
1407simandl #echo -n $wl_macparam | awk '{print $1,$2" "}'
1415simandl w_bar
142 fi
1434simandl done
14411simandl 
145 echo
1462simandl} # w_master
147 
148######################################################################
149w_iface()
15011simandl{ wl_iwctxt=`$wl_iwccmd $wl_iface 2>/dev/null | grep -v 'Device|Some|Extension' | sed 's/ Nick/_Nick/g'`
1517simandl wl_mode=`echo $wl_iwctxt | awk '{print $5}' | sed 's/Mode://g'`
1522simandl if [ "a$wl_mode" = "aManaged" ]
153 then
154 w_managed
1558simandl elif [ "a$wl_mode" = "aAd-Hoc" ]
156 then
157 w_managed
1582simandl elif [ "a$wl_mode" = "aMaster" ]
159 then
160 w_master
161 else
162 echo $wl_iface $wlm_no_managed_or_master
163 echo
164 fi
165}
166 
167######################################################################
16811simandlw_version()
169{
170 echo wifimon $wl_version
171 exit 0
172}
173######################################################################
1745simandlw_help()
175{
1763simandl echo Pouziti: wifimon [param]
177 echo param:
17811simandl echo -v vypise verzi
1795simandl echo -html generovani html stranky
18011simandl echo -col barevny cyklicky vypis na obrazovku
1815simandl echo -once vypsani jen jednoho vypisu a pak program skonci
182 echo -oneline vypsani klientu na jednu linku
183 echo -wlan0 -wlan1 -wlan2 vypise jen uvedene karty a to v danem poctu a poradi
1843simandl echo bez parametru cyklicky vypis na obrazovku
1855simandl exit 0
186}
187######################################################################
188######################################################################
1892simandl 
1905simandlwl_unknown=""
191wl_cnt=1
192wcm_clear=1
193wcm_once=0
19411simandlwcm_col=0
1955simandlwcm_oneline=0
196wcm_html=0
197wcm_ifc=""
198 
1996simandl# parsing input parameters
2005simandlwhile [ "a$1" != "a" ]
201do
202 case $1 in
20311simandl -v)
204 w_version
205 ;;
2065simandl -help)
207 w_help
208 ;;
209 -once)
210 wcm_once=1
211 shift
212 ;;
213 -oneline)
214 wcm_oneline=1
215 shift
216 ;;
21711simandl -col)
218 wcm_col=1
2195simandl shift
220 ;;
221 -html)
222 wcm_html=1
223 shift
224 ;;
225 *)
226 wl_flg=0
227 for wl_iface in `ls $wl_hostap`
228 do
229 if [ "a-$wl_iface" = "a$1" ]
230 then
231 wcm_ifc="$wcm_ifc $wl_iface"
232 wl_flg=1
233 fi
234 done
235 if [ $wl_flg -eq 0 ]
236 then
237 wl_unknown="$wl_unknown$1 "
238 fi
239 shift
240 esac
241done
242 
2436simandl# printing the list of bad parameters (if there are some)
2445simandlif [ "a$wl_unknown" != "a" ]
245then
246 echo "$wlm_unknown $wl_unknown"
247 w_help
248fi
249 
2506simandl# if no interface is selected then all available are choosen
2515simandlif [ "a$wcm_ifc" = "a" ]
252then
253 wcm_ifc=`ls $wl_hostap`
254fi
255 
2566simandl# setting for old and last same value to avoid double clear after start
257wl_numcllast=0
258wl_numclold=0
259for wl_iface in $wcm_ifc
260do
261 wl_numcl=`ls $wl_hostap$wl_iface | grep -c 00`
262 wl_numcllast=$(($wl_numcllast + $wl_numcl))
263done
264wl_numclold=$wl_numcllast
265 
26611simandlif [ $wcm_col -eq 0 ]
2676simandlthen
268 w_bw
26911simandlelse
270 w_col
2716simandlfi
272 
273while [ 1 ]
2745simandl do
275 if [ $wl_numcllast -ne $wl_numclold ]
276 then
277 wl_numclold=$wl_numcllast
278 wcm_clear=1
279 fi
28011simandl if [ $wcm_clear -eq 1 -a $wcm_html -ne 1 ]
2815simandl then
2827simandl clear
2835simandl wcm_clear=0
284 fi
285 wl_numcllast=0
2867simandl if [ $wcm_html -eq 1 ]
2875simandl then
28811simandl w_bw
2897simandl echo $wl_header
290 for wl_iface in $wcm_ifc
291 do
292 w_iface
293 done
294 echo $wl_footer
295 else
29612simandl [ -e /usr/bin/tput ] && tput cup 0 0 || clear
2977simandl for wl_iface in $wcm_ifc
298 do
299 w_iface
300 done
3015simandl fi
30211simandl 
3035simandl if [ $wcm_once -eq 1 ]
304 then
305 exit 0
306 fi
307 sleep 1
3086simandldone
3095simandl 
310exit 0
311 

Powered by WebSVN 2.2.1