Skip to content

Instantly share code, notes, and snippets.

@jollyroger
Created October 24, 2009 07:42
Show Gist options
  • Save jollyroger/217430 to your computer and use it in GitHub Desktop.
Save jollyroger/217430 to your computer and use it in GitHub Desktop.
Automatic Wi-Fi the Debian-way
auto wlan0
mapping wlan0
script /usr/local/sbin/wlan-detect.sh
map HomeAP wlan0-home
map OfficeAP wlan0-office
iface wlan0-home inet dhcp
wpa-ssid HomeAP
wpa-psk HomeAccessPointPassphrase
wpa-key-mgmt WPA-PSK
wpa-pairwise TKIP CCMP
wpa-group TKIP CCMP
wpa-proto WPA RSN
iface wlan0-office inet dhcp
wpa-ssid OfficeAP
wpa-psk OfficeAccessPointPassphrase
wpa-key-mgmt WPA-PSK
wpa-pairwise TKIP CCMP
wpa-group TKIP CCMP
wpa-proto WPA RSN
#!/bin/sh
# Script for automatic mapping wireless network interface to available and known
# access point. For more details see interfaces(5) mapping options. Example
# interfaces(5) file is provided.
#
# Note that access point ESSID and first argument in ``map'' directive should
# match.
IFACE="$1"
CTRL_SOCKET="/var/run/wpa_supplicant"
# We cannot perform AP scanning until interface is down. Bring up wlan interface
# with wpa_supplicant and wait a little.
wpa_supplicant -i $IFACE -C $CTRL_SOCKET &
PID=$!
sleep 5
SCAN_RESULT=`mktemp`
iwlist $IFACE scan > $SCAN_RESULT
# Simple check of scanning results. Script stops searching when first AP is
# found.
while read SSID IFACE_ALIAS ; do
if ( grep "ESSID:\"$SSID\"" $SCAN_RESULT > /dev/null ) ; then
echo $IFACE_ALIAS
break
fi
done
# Come cleanup before exit.
kill $PID
rm $SCAN_RESULT
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment