#!/bin/sh dev=wlan1 #How many SSID's there is in the configuration file WC=`sudo cat /etc/wifi-radar.conf | grep "\[" | cut -d "[" -f 2 | cut -d "]" -f 1 | cat -n | wc -l` #Strength of network netstr=`cat /proc/net/wireless | grep $dev | awk {'print $3'} | cut -d "." -f 1` # Test network testnet() { if [ $netstr > 0 ] then echo "Network seams to be up, lets test some more" echo "Checking what your gateway is please wait" netgw=`sudo route 2> /dev/null | grep $dev | grep default | awk {'print $2'}` echo "Checking your ping to $netgw (Your gateway) please wait." netping=`ping $netgw -c 1 2> /dev/null | grep bytes | grep time | awk {'print $7'} | cut -d "=" -f 2` if [ $netping > 0 ] then echo "Your Ping is $netping" echo "Network is functional" exit # Network is working, why continue ? Exit script exit else #network is not working, lets try and fix it. echo "Your Ping is $netping Not what it should be" connectnet fi else echo "Does not seam to work lets start working on it :)" connectnet fi } connectnet() { # wifi-radar config file parser X=0 until [ $X = $WC ] ; do X=`calc $X + 1` NR=`sudo cat /etc/wifi-radar.conf | grep "\[" | cut -d "[" -f 2 | cut -d "]" -f 1 | cat -n | grep $X | cut -d "$X" -f 2` if [ $NR = DEFAULT ] then echo "0" > /dev/null else # Return SSID sudo iwconfig $dev ESSID $NR cssid=`sudo iwconfig 2> /dev/null | grep $dev | grep ESSID | awk {'print $4'} | cut -d ":" -f 2 | cut -d '"' -f 2` printf "Trying to connect to $NR " if [ "$cssid" = $NR ] then printf "successfull \n" sudo dhclient $dev exit else printf "not successfull \n" fi fi done } testnet