1 | 2 | simandl | #!/bin/bash |
2 | 3 | simandl | # authors : Petr Simandl www.simandl.cz |
3 | | | # |
4 | | | # release date : 1/1/2003 |
5 | 2 | simandl | # name : wifimon |
6 | 3 | simandl | # version : 0.2 beta |
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 | 3 | simandl | wl_webpage="/tmp/wifimon.htm" |
18 | | | wl_header="<html><head><meta HTTP-EQUIV=\"Refresh\" CONTENT=\"1\"><title>Wifimon @ `$wl_hnmcmd`</title></head><body BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\"><pre>" |
19 | | | wl_header_static="<html><head><title>Wifimon @ `$wl_hnmcmd`</title></head><body BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\"><pre>" |
20 | | | wl_footer="</pre></body></html>" |
21 | | | |
22 | 2 | simandl | wlm_no_managed_or_master=" neni ani Master ani Managed..." |
23 | | | wlm_number_of_clients="Pocet asociovanych klientu : " |
24 | | | #wlm_no_managed_or_master=" is not Master or Managed..." |
25 | | | #wlm_number_of_clients="Number of associated clients : " |
26 | | | ###################################################################### |
27 | | | w_bar() |
28 | | | { |
29 | | | until [ "$wl_cnt" -eq -1 ] |
30 | | | do |
31 | | | printf "=" |
32 | | | wl_cnt=$(($wl_cnt - 1 )) |
33 | | | done |
34 | | | printf " \n" |
35 | | | } # w_bar |
36 | | | |
37 | | | ###################################################################### |
38 | | | w_managed() |
39 | | | { echo $wl_iwctxt | awk '{print $1,$3,$4,$5" "}' |
40 | 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 |
41 | | | echo $wl_iwctxt | awk '{print $9,$6,$11" "}' |
42 | 2 | simandl | #echo $wl_iwctxt | awk '{print $27,$28,$29,$31,$32" "}' |
43 | | | #cat $wl_wireless | grep $wl_iface |
44 | | | wl_wtxt=`cat $wl_wireless | grep $wl_iface | awk '{print $3,$4,$5}' | sed 's/\.//g'` |
45 | | | wl_quality=`echo $wl_wtxt | awk '{print $1}'` |
46 | | | wl_signal=`echo $wl_wtxt | awk '{print $2}'` |
47 | | | wl_signal=$(($wl_signal - 256)) |
48 | | | wl_noise=`echo $wl_wtxt | awk '{print $3}'` |
49 | | | wl_noise=$(($wl_noise - 256)) |
50 | | | echo Quality:$wl_quality/92 Signal level:$wl_signal Noise level:$wl_noise |
51 | | | wl_cnt=$wl_quality |
52 | | | w_bar |
53 | | | #wl_cnt=$(($wl_cnt + 100)) |
54 | | | #w_bar |
55 | | | echo |
56 | | | } # w_managed |
57 | | | |
58 | | | ###################################################################### |
59 | | | w_master() |
60 | | | { echo $wl_iwctxt | awk '{print $1,$3,$4,$5" "}' |
61 | | | echo $wl_iwctxt | awk '{print $6,$9,$11" "}' |
62 | | | |
63 | | | wl_numcl=`ls $wl_hostap$wl_iface | grep -c 00` |
64 | | | echo $wlm_number_of_clients $wl_numcl |
65 | 3 | simandl | for wl_mac in `ls $wl_hostap$wl_iface | grep 00 ` |
66 | 2 | simandl | do |
67 | | | wl_macparam=`cat $wl_hostap$wl_iface/$wl_mac | grep -E 'last_rx|last_tx'` |
68 | | | wl_cnt=`echo $wl_macparam | awk '{print $5}' | sed 's/signal=//g'` |
69 | 3 | simandl | wl_umac=`echo $wl_mac | tr abcdef ABCDEF` |
70 | | | wl_ipc=`cat $wl_arp | grep $wl_umac | awk '{print $1}'` # IP adresa peeru z arp tabulky |
71 | | | echo $wl_ipc $wl_umac Signal $wl_cnt $wl_macparam | awk '{print $1,$2,$3,$4,$5" "}' |
72 | 2 | simandl | w_bar |
73 | | | done |
74 | | | |
75 | | | echo |
76 | | | } # w_master |
77 | | | |
78 | | | ###################################################################### |
79 | | | w_iface() |
80 | | | { wl_iwctxt=`$wl_iwccmd $wl_iface | grep -v 'Device|Some|Extension' | sed 's/ Nick/_Nick/g'` |
81 | | | wl_mode=`echo $wl_iwctxt | awk '{print $5}' | sed 's/Mode://g'` |
82 | | | if [ "a$wl_mode" = "aManaged" ] |
83 | | | then |
84 | | | w_managed |
85 | | | elif [ "a$wl_mode" = "aMaster" ] |
86 | | | then |
87 | | | w_master |
88 | | | else |
89 | | | echo $wl_iface $wlm_no_managed_or_master |
90 | | | echo |
91 | | | fi |
92 | | | } |
93 | | | |
94 | | | ###################################################################### |
95 | | | ###################################################################### |
96 | | | |
97 | 3 | simandl | case $1 in |
98 | | | -help) |
99 | | | echo Pouziti: wifimon [param] |
100 | | | echo param: |
101 | | | echo -htm cyklicke generovani stranky s 1s obnonovanim |
102 | | | echo -htm1 jedna staticka stranka |
103 | | | echo bez parametru cyklicky vypis na obrazovku |
104 | 2 | simandl | |
105 | 3 | simandl | ;; |
106 | | | -htm1) |
107 | | | echo $wl_header_static > $wl_webpage |
108 | | | for wl_iface in `ls $wl_hostap` |
109 | | | do |
110 | | | w_iface >> $wl_webpage |
111 | | | done |
112 | | | echo $wl_footer >> $wl_webpage |
113 | | | ;; |
114 | | | -htm) |
115 | | | while [ 1 ] |
116 | | | do |
117 | | | echo $wl_header > $wl_webpage.tmp |
118 | | | for wl_iface in `ls $wl_hostap` |
119 | | | do |
120 | | | w_iface >> $wl_webpage.tmp |
121 | | | done |
122 | | | echo $wl_footer >> $wl_webpage.tmp |
123 | | | cp $wl_webpage.tmp $wl_webpage |
124 | | | sleep 1 |
125 | 2 | simandl | done |
126 | 3 | simandl | ;; |
127 | | | *) |
128 | | | clear |
129 | | | while [ 1 ] |
130 | | | do |
131 | | | tput cup 0 0 |
132 | | | for wl_iface in `ls $wl_hostap` |
133 | | | do |
134 | | | w_iface |
135 | | | done |
136 | | | sleep 1 |
137 | | | done |
138 | | | esac |
139 | 2 | simandl | |
140 | | | exit 0 |
141 | | | |
142 | | | |