jablonka.czprosek.czf

wifimon

Subversion Repositories:
[/] [trunk/] [wifimon] - Rev 11 Go to most recent revision

Compare with Previous - Blame - Download


#!/bin/bash
# authors      : Petr Simandl www.simandl.cz
#              : Fyzik, Covex 
# release date : 1/8/2003 
# name         : wifimon
# description  : hostap powered wifi card monitoring
# license      : GPL

wl_version="0.4beta6"

wl_iwccmd="/usr/local/sbin/iwconfig"
wl_ifccmd="/sbin/ifconfig"
wl_hnmcmd="/bin/hostname"
wl_hostap="/proc/net/hostap/"
wl_wireless="/proc/net/wireless"
wl_arp="/proc/net/arp"
wl_dhcpcnf="/etc/dhcpd.conf"


wl_webpage="/tmp/wifimon.htm"
wl_header="<html><head><meta HTTP-EQUIV=\"Refresh\" CONTENT=\"3\"><title>Wifimon @ `$wl_hnmcmd`</title></head><body BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\"><pre>"
wl_footer="</pre></body></html>"

wlm_no_managed_or_master=" neni ani Master ani Managed..."
wlm_number_of_clients="Pocet asociovanych klientu : " 
wlm_unknown="Nezname parametry nebo neplatne jmeno rozhrani : "
#wlm_no_managed_or_master=" is not Master or Managed..."
#wlm_number_of_clients="Number of associated clients : " 

wlch_signal="="
wlch_noise="*"

######################################################################
w_col()
{
wlc_red=`tput setaf 1`
wlc_green=`tput setaf 2`
wlc_brown=`tput setaf 3`
wlc_blue=`tput setaf 4`
wlc_magenta=`tput setaf 5`
wlc_lblue=`tput setaf 6`
wlc_grey=`tput setaf 7`
wlc_std=`tput sgr0`

wlc_ip=$wlc_lblue       # ip address color
wlc_mac=$wlc_magenta    # mac address color
wlc_sig=$wlc_red        # signal number color
wlc_bar=$wlc_green      # signal bar color
}
######################################################################
w_bw()
{
  wlc_ip=""
  wlc_mac=""
  wlc_sig=""
  wlc_bar=""
  wlc_std=""
}
######################################################################
w_bar()
{
  echo -n "${wlc_bar}"
  wl_neg=`expr $wl_cnt \< 0 `
  if [ "$wl_neg" -eq 1 ]
  then
    wl_cnt=$(($wl_cnt * -1 ))
    wl_bar=$wlch_noise
  else
    wl_bar=$wlch_signal
  fi
  until [ "$wl_cnt" -eq -1 ]
  do
    echo -n "$wl_bar"
    wl_cnt=$(($wl_cnt - 1 ))
  done  
  printf "        \n"
  echo -n "${wlc_std}"
#  tput sgr0
} # w_bar

######################################################################
w_managed()
{ echo $wl_iwctxt | awk '{print $1,$3,$4,$5"  "}' 
  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 
  echo $wl_iwctxt | awk '{print $9,$6,$11"  "}' 
  #echo $wl_iwctxt | awk '{print $27,$28,$29,$31,$32"  "}' 
  #cat $wl_wireless | grep $wl_iface
  wl_wtxt=`cat $wl_wireless | grep $wl_iface | awk '{print $3,$4,$5}' | sed 's/\.//g'`
  wl_quality=`echo $wl_wtxt | awk '{print $1}'`
  wl_signal=`echo $wl_wtxt | awk '{print $2}'`
  wl_signal=$(($wl_signal - 256))
  wl_noise=`echo $wl_wtxt | awk '{print $3}'`
  wl_noise=$(($wl_noise - 256))
  echo "Quality:${wlc_sig}$wl_quality${wlc_std}/92 Signal level:$wl_signal Noise level:$wl_noise "
  wl_cnt=$wl_quality
  w_bar
  #wl_cnt=$(($wl_cnt + 100))
  #w_bar
  echo
} # w_managed

######################################################################
w_master()
{ if [ $wcm_oneline -eq 0 ]
  then
    echo $wl_iwctxt | awk '{print $1,$3,$4,$5"  "}' 
    echo $wl_iwctxt | awk '{print $6,$9,$11"  "}' 
  else
    echo $wl_iwctxt | awk '{print $1,$4,$5,$6,$11"  "}' | sed 's/ [^": ]*:/ /g'
  fi

  wl_numcl=`ls $wl_hostap$wl_iface | grep -c 00`
  echo $wlm_number_of_clients $wl_numcl
  wl_numcllast=$(($wl_numcllast + $wl_numcl))
  for wl_mac in `ls $wl_hostap$wl_iface | grep 00 ` 
  do
    wl_macparam=`cat $wl_hostap$wl_iface/$wl_mac | grep -E 'last_rx|last_tx' | sed 's/last_//g'`
    wl_signal=`echo $wl_macparam | awk '{print $5}' | sed 's/signal=//g'`
    wl_silence=`echo $wl_macparam | awk '{print $4}' | sed 's/silence=//g'`
    wl_cnt=$(($wl_signal - $wl_silence))
    wl_ipc=`cat $wl_arp | grep -i $wl_mac | awk '{print $1}'`   # IP adresa peeru z arp tabulky
    wl_name=`cat $wl_dhcpcnf | grep -i $wl_mac | awk '{print $2}'`
    if [ $wcm_oneline -eq 0 ]
    then
      echo -n "$wl_name "
      echo -n "${wlc_ip}$wl_ipc${wlc_std} "
      echo -n "${wlc_mac}$wl_mac${wlc_std} Signal ${wlc_sig}$wl_cnt${wlc_std} "
      echo  $wl_macparam | awk '{print $1,$2"  "}' 
      w_bar
    else
      echo -n "$wl_name "
      #echo -n "${wlc_ip}$wl_ipc${wlc_std} "
      echo -n "${wlc_mac}$wl_mac${wlc_std} ${wlc_sig}$wl_cnt${wlc_std} "
      #echo -n $wl_macparam | awk '{print $1,$2"  "}' 
      w_bar
    fi
  done

  echo
} # w_master

######################################################################
w_iface()
{ wl_iwctxt=`$wl_iwccmd $wl_iface 2>/dev/null | grep -v 'Device|Some|Extension' | sed 's/  Nick/_Nick/g'`
  wl_mode=`echo $wl_iwctxt | awk '{print $5}' | sed 's/Mode://g'`
  if [ "a$wl_mode" = "aManaged" ]
  then
    w_managed
  elif [ "a$wl_mode" = "aAd-Hoc" ]
  then
    w_managed
  elif [ "a$wl_mode" = "aMaster" ]
  then
    w_master
  else
    echo $wl_iface $wlm_no_managed_or_master
    echo
  fi  
}

######################################################################
w_version()
{
  echo wifimon $wl_version
  exit 0
}
######################################################################
w_help()
{
  echo Pouziti: wifimon [param]
  echo param:
  echo -v vypise verzi
  echo -html generovani html stranky
  echo -col barevny cyklicky vypis na obrazovku
  echo -once vypsani jen jednoho vypisu a pak program skonci
  echo -oneline vypsani klientu na jednu linku
  echo -wlan0 -wlan1 -wlan2 vypise jen uvedene karty a to v danem poctu a poradi 
  echo bez parametru cyklicky vypis na obrazovku
  exit 0
}
######################################################################
######################################################################

wl_unknown=""
wl_cnt=1
wcm_clear=1
wcm_once=0
wcm_col=0
wcm_oneline=0
wcm_html=0
wcm_ifc=""

# parsing input parameters
while [ "a$1" != "a" ]
do
  case $1 in
  -v)
     w_version
  ;;
  -help)
     w_help
  ;;
  -once)
    wcm_once=1
    shift
  ;;
  -oneline)
    wcm_oneline=1
    shift
  ;;
  -col)
    wcm_col=1
    shift
  ;;
  -html)
    wcm_html=1
    shift
  ;;
  *)
    wl_flg=0
    for wl_iface in `ls $wl_hostap`
    do 
      if [ "a-$wl_iface" = "a$1" ]
      then
        wcm_ifc="$wcm_ifc $wl_iface"
        wl_flg=1
      fi
    done
    if [ $wl_flg -eq 0 ]
    then
      wl_unknown="$wl_unknown$1 "
    fi
    shift
  esac
done

# printing the list of bad parameters (if there are some)
if [ "a$wl_unknown" != "a" ]
then
  echo "$wlm_unknown $wl_unknown"
  w_help
fi

# if no interface is selected then all available are choosen
if [ "a$wcm_ifc" = "a" ]
then
    wcm_ifc=`ls $wl_hostap`
fi

# setting for old and last same value to avoid double clear after start
wl_numcllast=0
wl_numclold=0
for wl_iface in $wcm_ifc
do 
  wl_numcl=`ls $wl_hostap$wl_iface | grep -c 00`
  wl_numcllast=$(($wl_numcllast + $wl_numcl))
done
wl_numclold=$wl_numcllast

if [ $wcm_col -eq 0 ]
then
  w_bw
else
  w_col
fi

while [ 1 ]
  do
    if [ $wl_numcllast -ne $wl_numclold ]
    then
      wl_numclold=$wl_numcllast
      wcm_clear=1
    fi
    if [ $wcm_clear -eq 1 -a $wcm_html -ne 1 ]
    then
      clear
      wcm_clear=0
    fi
    wl_numcllast=0
    if [ $wcm_html -eq 1 ]
    then
      w_bw
      echo $wl_header
      for wl_iface in $wcm_ifc
      do 
        w_iface
      done
      echo $wl_footer
    else
      tput cup 0 0
      for wl_iface in $wcm_ifc
      do 
        w_iface
      done
    fi

    if [ $wcm_once -eq 1 ]
    then
      exit 0
    fi 
    sleep 1
done

exit 0


Powered by WebSVN 2.2.1