set_mac() { local interface=$1 local mac_address=$2 if has ifconfig; then current_mac=$(ifconfig "$interface" | awk '/ether/ {print $2}') if [[ "${current_mac,,}" == "${mac_address,,}" ]]; then return fi ifconfig "$interface" down if [[ "$OSTYPE" == "linux-gnu" ]]; then ifconfig "$interface" hw ether "$mac_address" else ifconfig "$interface" ether "$mac_address" fi ifconfig "$interface" up elif has ip; then ip link set dev "$interface" down ip link set dev "$interface" address "$mac_address" ip link set dev "$interface" up else die "no suitable program found to configure the network interface, need iproute2 or ifconfig" fi }