#! /bin/sh ## Syntax: ## # wifi [] ## ## If no argument is provided, print out a list of all known places, along ## with the corresponding essid. The more recent places will be shown first, ## so you can |head(1) the output if there are many. ## If you provide an place name, it will be looked up and the parameters that ## were recorded for that place will be applied. ## ## Other possible syntax: ## # wifilist ## ## Checks the available networks against the ones you know. ## ## Places definitions are stored in /etc/network/foo, with the following ## kind of contents: ## essid "My Home" ## key 0123456789 ## ## Any argument that is valid for iwconfig(8) may be used. ## ## Author: davux #IFACES="eth0 wifi0" IFACES="wlan0" DIR="/etc/network/wlan" for iface in $IFACES; do ifconfig "$iface" up done if [ `basename "$0"` = 'wifilist' ]; then for iface in $IFACES; do iwlist "$iface" scan | /bin/grep -i 'quality\|essid' | xargs | sed 's/Quality/\n&/g' done exit fi usage() { example="$1" name=`basename "$0"` echo '' echo "Usage: $name " echo "Example: $name $example" echo '' } draw_chart() { dir="$1" off='' color='' underl='' echo "$color ___________________________________________________$off" >&2 printf " $color|$underl %-20s | %-25s $off$color|"'\n' ' Place' ' ESSID' >&2 grep -v '^#' `ls -t "$dir"/*` | grep essid | sed 's|'"$dir"'/\([^:]*\):essid \(.*\)|\1 \2|' | xargs printf " $color|$off %-20s $color|$off %-25s $color|$off"'\n' echo " $color"'|'"______________________|____________________________$color|$off" >&2 } main_iface=`echo "$IFACES" | sed 's/ .*//'` if [ "$1" ]; then for iface in $IFACES; do ifdown "$iface" 2> /dev/null ifconfig "$iface" up -promisc iwconfig "$iface" key off mode Managed done killall -q dhclient{,3} sleep 1 path="$DIR/$1" if [ -r "$path" ]; then shift grep -v '^[ ]*#' "$path" | xargs echo iwconfig "$main_iface" $@ grep -v '^[ ]*#' "$path" | xargs iwconfig "$main_iface" $@ touch "$path" else echo "E: Could not find profile '$1' in '$DIR'." >&2 exit 1 fi else draw_chart "$DIR" first=`ls -t "$DIR"/* | head -n1 | xargs basename` usage "$first" >&2 fi