home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / doc / ifupdown / examples / check-mac-address.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  2005-05-12  |  496 b   |  20 lines

  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
  20.