Random MAC Address generator

I’ve made a bash script that changes the network interface’s MAC address. The script is based on three of the latest posts, first it ask the user for the network interface that will be modified, then it generates some random numbers, convert them from decimal to hexadecimal, and finally it changes the MAC address.

I’m sure this is a dirty script and there might be better ways to do this task, but it seems to work fine, altought I don’t know for sure if it does work in every situation, but yes, it does the trick:

#! /bin/bash
echo "Name the interface you want to change:"
read interface
n2=$(printf '%x\n' $[($RANDOM % 256)])
n3=$(printf '%x\n' $[($RANDOM % 256)])
n4=$(printf '%x\n' $[($RANDOM % 256)])
n5=$(printf '%x\n' $[($RANDOM % 256)])
n6=$(printf '%x\n' $[($RANDOM % 256)])
newmac=00:$n2:$n3:$n4:$n5:$n6
/etc/init.d/networking stop
ifconfig $interface hw ether $newmac
/etc/init.d/networking start
echo The new MAC address for $interface is: $newmac

Keep in mind that you need root privileges to run this script.

Hope you find this usefull. Download: randommac.sh

0 comments

Please insert the result of the arithmetical operation from the following image
Enter the result of the arithmetical operation from this image