#!/bin/bash
# Authors: Steven Shiau <steven _at_ clonezilla org>, Ceasar Sun <ceasar_dot_sun_at_gmail com>
# License: GPL
# Description: Get the MAC address of network card interface

ethx=$1
export LC_ALL=C

Usage() {
  echo "Get the MAC address of network card interface" 
  echo "Usage:"
  echo "$(basename $0) INTERFACE"
  echo "Ex: $(basename $0) eth0"
}

[ -z "$ethx" ] && Usage && exit 1
if ! LC_ALL=C ip link show dev $ethx >/dev/null 2>&1; then
   exit 1
fi
# Ex: link/ether 00:0c:29:81:a0:d5 brd ff:ff:ff:ff:ff:ff

_nic_mac=$(LC_ALL=C ip link show dev $ethx | awk '/link\// {print $2}' | tr '[A-Z]' '[a-z]')
echo $_nic_mac
exit 0
