Git init
[external/ifupdown.git] / examples / check-mac-address.sh
1 #!/bin/sh
2 #
3 # Checks if the given interface matches the given ethernet MAC.
4 # If it does it exits with 0 (success) status;
5 # if it doesn't then it exists with 1 (error) status.
6
7 set -e
8
9 export LANG=C
10
11 if [ ! "$2" ] ; then
12         echo "Usage: $0 IFACE targetMAC"
13         exit 1
14 fi
15 iface="$1"
16 targetmac=`echo "$2" | sed -e 'y/ABCDEF/abcdef/'`
17 mac=$(/sbin/ifconfig "$iface" | sed -n -e '/^.*HWaddr \([:[:xdigit:]]*\).*/{s//\1/;y/ABCDEF/abcdef/;p;q;}')
18
19 if [ "$targetmac" = "$mac" ]; then exit 0; else exit 1; fi