evenet/lib/mac.bash

32 lines
960 B
Bash

set_mac() {
local interface=$1
local mac_address=$2
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
current_mac=$(ifconfig "$interface" | awk '/ether/ {print $2}')
if [[ "${current_mac,,}" == "${mac_address,,}" ]]; then
return
fi
ifconfig "$interface" down
if [[ "$OSTYPE" == "freebsd"* ]]; then
ifconfig "$interface" link "$mac_address"
elif [[ "$OSTYPE" == "darwin"* ]]; then
ifconfig "$interface" lladdr "$mac_address"
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
}