You are not logged in.

Here's a little bash script that looks at the available wifi APs that your card can see, and automatically connects you to the AP with the highest quality and that is also unencrypted. I'm just posting it in case anyone wants to improve upon it or use it. And yes, my bash knowledge kinda sucks.
Just call it like "wifi.sh wlan0" as root.
#!/bin/bash
# Finds the strongest unencrypted AP and tries to connect to it via dhcp
# Call this script like "wifi.sh wlan0"
interface=$1
iwlist $interface scan > blah
NumAPs=`cat blah | grep ESSID | wc -l`
BestAP=0
BestQuality=-1
for i in `seq 1 $NumAPs`;
do
    # Check if AP is encrypted
    Encryption=`cat blah | grep Encryption | head -n$i | tail -n1 | cut -d":" -f2`
    if [ $Encryption = "off" ]; then
        # Find AP with the highest quality
        QUALITY=`cat blah | 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 blah | grep ESSID | head -n$BestAP | tail -n1 | cut -d""" -f2`
    echo ESSID=$ESSID
    MODE=`cat blah | grep Mode | head -n$BestAP | tail -n1 | cut -d":" -f2`
    echo Mode=$MODE
    CHANNEL=`cat blah | 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
    rm blah
fiI am a gated community.
Offline
Thx for the script, i add some little *fancy* stuff to it
#!/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[My Blog] | [My Repo] | [My AUR Packages]
Offline

Thanks _Gandalf_! I was planning on eventually looking into how to verify if the user is root...  
I also have no idea if it is actually finding the "strongest" AP or not. For whatever reason, iwlist always shows 0/100 for the Quality of every AP. Ah well.
I am a gated community.
Offline
You might find it worth mentioning what chipset your card uses.
Some chipsets report it entirely differently, others dont report it at all. ndiswrapper doesnt.
Offline

Ah yes, it's ndiswrapper. It never dawned on me that that would have something to do with it, thanks for the info iphitus.
I am a gated community.
Offline
this script will sure come in handy on the road, I was looking for something similar before and I'm too lazy to write on myself ^^
-kupo-
Offline

Any volunteers for making a "Bash script to connect to strongest encrypted wifi AP"?    
 
Cheers Sigi
Haven't been here in a while. Still rocking Arch. 
Offline
This script is awesome, thanks guys.  I always had trouble where I would connect to a network and then drop every few minutes and have to reconnect, but I've been connected now for about an hour without any problems   
Offline

Sweet script. Is there a way to exclude one AP? The problem being my school has campus wide wifi which is nice, but also clogged with ton's of kids who suck and are using it the same time I am, so I want to find the n00bs with open wifi on their new routers that they haven't secured. It may be lower quality, but it's probably going to be faster for me.
Extending this script to read a preference file or something would be cool. Priorities like wpa_supplicant. mmmm
[edit]
@Sigi:  It's my understanding that wpa_supplicant can do that for you.
Offline
Trying this at home, I encounter the following error:
jakob@scripts $ s ./wconnect ath0
./wconnect: line 39: [: Quality=10: integer expression expected
my full iwlist ath0 scan looks like so:
ath0 Scan completed :
Cell 01 - Address: 00:04:0E:6C:4E:9C
ESSID:"keller"
Mode:Master
Frequency:2.412 GHz (Channel 1)
Quality=10/94 Signal level=-86 dBm Noise level=-95 dBm
Encryption key:off
Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 22 Mb/s
6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s
36 Mb/s; 48 Mb/s; 54 Mb/s
Extra:bcn_int=100
Can't believe, that I'm the only one with that error?
Offline

For whatever reason, your quality line uses an equal sign whereas every other line of your scan has a colon (and most people have a colon for every line). Too weird..
Anyway, give this a shot:
#!/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
isNotInteger()
{
    x=$1
    case $x in
        *[!0-9])
            return 0 ;;
        *)
            return 1 ;;
    esac
} 
# 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 isNotInteger "$QUALITY"; then
        # If we didn't find an integer, try this instead:
        QUALITY=`cat $TEMP | grep Quality | head -n$i | tail -n1 | cut -d"=" -f2 | cut -d"/" -f1 | sed 's/ //g'`
      fi
      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 $LOCKI am a gated community.
Offline