evenet/lib/mac.bash

32 lines
960 B
Bash
Raw Normal View History

2015-02-19 08:36:40 +00:00
set_mac() {
local interface=$1
local mac_address=$2
2015-02-21 08:41:13 +00:00
if has ip; then
current_mac=$(ip addr show dev evenet | awk '/link\/ether/ { print $2 }')
if [[ "${current_mac,,}" == "${mac_address,,}" ]]; then
return
fi
ip link set dev "$interface" down
ip link set dev "$interface" address "$mac_address"
ip link set dev "$interface" up
elif has ifconfig; then
2015-02-19 08:36:40 +00:00
current_mac=$(ifconfig "$interface" | awk '/ether/ {print $2}')
if [[ "${current_mac,,}" == "${mac_address,,}" ]]; then
return
fi
ifconfig "$interface" down
2015-02-21 08:41:13 +00:00
if [[ "$OSTYPE" == "freebsd"* ]]; then
ifconfig "$interface" link "$mac_address"
elif [[ "$OSTYPE" == "darwin"* ]]; then
ifconfig "$interface" lladdr "$mac_address"
2015-02-19 08:36:40 +00:00
else
ifconfig "$interface" ether "$mac_address"
fi
ifconfig "$interface" up
else
die "no suitable program found to configure the network interface, need iproute2 or ifconfig"
fi
}