![]() |
2008-08-29
, 15:28
|
Posts: 14 |
Thanked: 2 times |
Joined on Aug 2008
|
#1
|
![]() |
2008-08-29
, 16:03
|
Posts: 14 |
Thanked: 2 times |
Joined on Aug 2008
|
#2
|
![]() |
2008-08-29
, 16:11
|
|
Posts: 1,605 |
Thanked: 1,601 times |
Joined on Mar 2007
@ Southern California
|
#3
|
![]() |
2008-08-29
, 16:25
|
Posts: 14 |
Thanked: 2 times |
Joined on Aug 2008
|
#4
|
![]() |
2008-08-29
, 18:36
|
|
Posts: 1,648 |
Thanked: 2,122 times |
Joined on Mar 2007
@ UNKLE's Never Never Land
|
#5
|
![]() |
2008-08-29
, 19:55
|
|
Posts: 716 |
Thanked: 236 times |
Joined on Dec 2007
|
#6
|
![]() |
2008-08-29
, 22:25
|
Posts: 14 |
Thanked: 2 times |
Joined on Aug 2008
|
#7
|
![]() |
2008-08-30
, 13:02
|
|
Posts: 145 |
Thanked: 18 times |
Joined on Aug 2008
@ Vancouver, BC
|
#8
|
![]() |
2008-08-30
, 14:58
|
Posts: 14 |
Thanked: 2 times |
Joined on Aug 2008
|
#9
|
![]() |
2008-08-30
, 16:48
|
Posts: 14 |
Thanked: 2 times |
Joined on Aug 2008
|
#10
|
#!/bin/bash
# Finds the strongest unencrypted AP and tries to connect to it via dhcp
# Call this script like "wifi.sh wlan0"
TEMP=/tmp/bestap.tmp
LOCK=/var/lock/bestap.lock
if [ `whoami` != "root" ];then
echo "Sorry, you need to be root to run this program"
exit 1
fi
if [[ -z $1 ]];then
echo "USAGE: $0 device"
exit 1
else
interface=$1
fi
# Checking for lock
if [[ -e $LOCK ]];then
exit 1; # Too simply nothing to do here
else
touch $TEMP $LOCK
fi
# Proggy
iwlist $interface scan > $TEMP
NumAPs=`cat $TEMP | grep ESSID | wc -l`
BestAP=0
BestQuality=-1
for i in `seq 1 $NumAPs`;
do
# Check if AP is encrypted
Encryption=`cat $TEMP | grep Encryption | head -n$i | tail -n1 | cut -d":" -f2`
if [ $Encryption = "off" ]; then
# Find AP with the highest quality
QUALITY=`cat $TEMP | grep Quality | head -n$i | tail -n1 | cut -d":" -f2 | cut -d"/" -f1 | sed 's/ //g'`
if [ "$QUALITY" -gt "$BestQuality" ]; then
BestQuality=$QUALITY
BestAP=$i
fi
fi
done
if [ $BestAP -gt 0 ]; then
# Yay, we found an unencrypted AP:
echo Connecting to...
ESSID=`cat $TEMP | grep ESSID | head -n$BestAP | tail -n1 | cut -d""" -f2`
echo ESSID=$ESSID
MODE=`cat $TEMP | grep Mode | head -n$BestAP | tail -n1 | cut -d":" -f2`
echo Mode=$MODE
CHANNEL=`cat $TEMP | grep Channel | head -n$BestAP | tail -n1 | cut -d"(" -f2 | sed 's/Channel //g' | sed 's/)//g'`
echo Channel=$CHANNEL
# Connect
iwconfig $interface essid $ESSID mode $MODE channel $CHANNEL
if [ -e /etc/dhcpc/dhcpcd-${interface}.pid ]; then
rm /etc/dhcpc/dhcpcd-${interface}.pid
fi
dhcpcd $interface
# Cleanup
fi
rm -f $TEMP $LOCK