| 1 | #!/bin/bash |
| 2 | # Authors: Steven Shiau <steven _at_ clonezilla org>, Ceasar Sun <ceasar_dot_sun_at_gmail com> |
| 3 | # License: GPL |
| 4 | # Description: Get the MAC address of network card interface |
| 5 | |
| 6 | # Load DRBL setting and functions |
| 7 | DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}" |
| 8 | |
| 9 | . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions |
| 10 | |
| 11 | # |
| 12 | ethx=$1 |
| 13 | export LC_ALL=C |
| 14 | |
| 15 | Usage() { |
| 16 | echo "Get the MAC address of network card interface" |
| 17 | echo "Usage:" |
| 18 | echo "$(basename $0) INTERFACE" |
| 19 | echo "Ex: $(basename $0) eth0" |
| 20 | } |
| 21 | |
| 22 | [ -z "$ethx" ] && Usage && exit 1 |
| 23 | if ! LC_ALL=C ip link show dev $ethx >/dev/null 2>&1; then |
| 24 | exit 1 |
| 25 | fi |
| 26 | # Ex: link/ether 00:0c:29:81:a0:d5 brd ff:ff:ff:ff:ff:ff |
| 27 | |
| 28 | _nic_mac=$(LC_ALL=C ip link show dev $ethx | awk '/link\// {print $2}' | tr '[A-Z]' '[a-z]') |
| 29 | echo $_nic_mac |
| 30 | exit 0 |