1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
#!/bin/sh
#
# test-wireless
#
# Usage:
# test-wireless IFACE [mac MACADDRESS] [essid ESSID]
#
# This tests whether the current interface has the appropriate MAC address
# and/or the approprate ESSID
#
# MACADDRESS letters must be in upper case
#
# Licensed under the GNU GPL. See /usr/share/common-licenses/GPL.
#
# History
# Oct 2004: Written by Thomas Hood
set -o errexit # -e
set -o noglob # -f
MYNAME="$(basename $0)"
PATH=/sbin:/bin
report_err() { echo "${MYNAME}: Error: $*" >&2 ; }
do_sleep() { LANG=C sleep "$@" ; }
IFACE="$1"
[ "$IFACE" ] || { report_err "Interface not specified. Exiting." ; exit 1 ; }
shift
while [ "$1" ] ; do
case "$1" in
mac)
MAC_ADDRESS="$2"
shift
;;
essid)
ESSID="$2"
shift
;;
esac
shift
done
[ "$MAC_ADDRESS" ] || [ "$ESSID" ] || { report_err "Neither AP MAC address nor ESSID specified. Exiting." ; exit 1 ; }
FAILED=0
do_sleep 0.5
if [ "$MAC_ADDRESS" ] ; then
ACTUAL_MAC_ADDRESS="$(iwgetid "$IFACE" --ap)"
ACTUAL_MAC_ADDRESS="${ACTUAL_MAC_ADDRESS#*Cell:}"
ACTUAL_MAC_ADDRESS="${ACTUAL_MAC_ADDRESS# }"
ACTUAL_MAC_ADDRESS="${ACTUAL_MAC_ADDRESS% }"
[ "$ACTUAL_MAC_ADDRESS" = "$MAC_ADDRESS" ] || FAILED=1
fi
if [ "$FAILED" = 0 ] && [ "$ESSID" ] ; then
ACTUAL_ESSID="$(iwgetid "$IFACE")"
ACTUAL_ESSID="${ACTUAL_ESSID#*ESSID:\"}"
ACTUAL_ESSID="${ACTUAL_ESSID%\"*}"
[ "$ACTUAL_ESSID" = "$ESSID" ] || FAILED=1
fi
exit "$FAILED"
|