#!/bin/bash # Find the available wireless interface: # FIXME this doesn't currently cope with more than one interface. IF=`cat /proc/net/wireless | awk 'NR>2 {print $1}' | tr -d ':'` if [ -z "${IF}" ] then echo "No wireless interfaces found" exit 1 fi tmpfile=`mktemp` trap "rm ${tmpfile}" 0 # Find the networks accessible via that interface. iwlist ${IF} scanning | awk ' BEGIN { essid=""; } { val=substr($0,index($0,":")+1); } /ESSID:/ { essid=substr(val,2,length(val)-2); } /Mode:/ { mode=val; } /Channel:/ { channel=val; } /Quality:/ { quality=substr(val,0,index(val,"/")); } /Encryption key:/ { enc=val; } /Cell / { if (essid!="") print quality,channel,enc,mode,essid; } END { if (essid!="") print quality,channel,enc,mode,essid; } ' | # Sort by quality sort -rn | # Format for dialog awk '{ quality=$1; channel=$2; enc=$3; mode=$4; essid=$5; printf("\"%s %s %s\" \"%s %s\" ",essid,channel,enc,mode,quality); }' > ${tmpfile} # Give up if no networks found. if [ ! -s ${tmpfile} ] then echo "No networks found" exit 1 fi trap "rm ${tmpfile}; clear" 0 # Present a menu of available networks. # (It would not be a bad idea to provide some way to enter details of networks that are # not broadcasting their ESSIDs.) eval dialog --menu \"Wireless Networks\" 15 50 15 `cat ${tmpfile}` 2>${tmpfile} case $? in 1) exit 0 ;; esac read essid channel enc < ${tmpfile} # Set up the interface according to the selection. iwconfig ${IF} essid ${essid} iwconfig ${IF} channel ${channel} # Is there encryption? case ${enc} in off) iwconfig ${IF} key off exit 0 ;; esac # This seems to be necessary for the RT2860STA driver: iwpriv ra0 set EncrypType=WEP # Ask for a password: dialog --insecure --passwordbox "Password for ${essid}" 15 50 2>${tmpfile} case $? in 1) exit 0 ;; esac # Tell the interface about the password. iwconfig ${IF} key "`cat ${tmpfile}`"