#!/bin/bash if [ $(id -u) -ne 0 ] || [ "$1" = "" ]; then exit 1; fi iface="$1" rmmod ath5k # otherwise DHCP is unreliable on restart modprobe ath5k ifconfig $iface up index=0 exec 3< <(iwlist wlan0 scanning | \ sed -n 's/^\s\+ESSID:"\([^"]\+\)"$/\1/p' | sort | uniq) while read -u 3 ap; do if [ "$DEBUGGING" ]; then echo aps[$index]="$ap" >&2; fi aps[$index]="$ap" index=$((index + 1)) done if [ "$DEBUGGING"]; then echo aps=${aps[@]} >&2; fi found="" while read essid scheme; do if [ "$DEBUGGING" ]; then echo checking $iface for \"$essid\" >&2; fi for index in $(seq 0 ${#aps[@]}); do #echo checking if \"${aps[$index]}\" = \"$essid\" >&2 if [ "${aps[$index]}" = "$essid" ]; then #echo "found: $scheme" >&2 found="$scheme" break fi done done if [ "$found" ]; then echo $found; echo found interface $found >&2; exit 0 else exit 1 fi