0

I'm trying to figure out a way to invoke the "mac clone" command found under the "setup" menu in DD-WRT v24SP2. I can do it in the GUI (of course), but I want to place it in a script so that I can cron and randomize it.

Perhaps it would be best if I explained my plight? What I want to create is a script that I can run that will randomly set the MAC address of the router to get a new IP address. I've tried many different scripts , but none seem to work with my router model (Buffalo WZR-HP-G300NH). After giving up on scripts, I decided to try using the built in "MAC clone" function in the GUI; It worked like a charm. Unfortunately, I can't exactly cron the GUI, nor can I have it select the MAC randomly from the GUI.

Here is what I have to set the MAC to a random value:

MAC=`(date; cat /proc/interrupts) | md5sum | sed -r 's/^(.{10}).*$/\1/; s/([0-9a-f]{2})/\1:/g; s/:$//;'`
echo "00:${MAC}"

The echoed value is the randomly generated MAC address (it always starts with 00, I know it's bad.).

So (bad grammar), the question I have is: How do I call whatever built-in function is used to clone the MAC address using the above script?

Thanks in advance!

2 Answers2

0

There are some command line options which I think you are looking for... these are as follows:

mac_clone_enable=1

1 turns the MAC cloning on and 0 turns it off

wan_hwaddr=00:AA:BB:CC:DD:EE

def_hwaddr=00:AA:BB:CC:DD:EE

The random MAC address you want goes in both... I am not sure what the difference is but in my configuration, they are both the same.

emtunc
  • 812
  • 2
  • 8
  • 17
0

Here is my full custom script which appears to work well:

MAC=`(date; cat /proc/interrupts) | md5sum | sed -r 's/^(.{10}).*$/\1/; s/([0-9a-f]{2})/\1:/g; s/:$//;'`
nvram set mac_clone_enable=1
nvram set wan_hwaddr="00:${MAC}"
nvram set def_hwaddr="00:${MAC}"
nvram commit
echo "00:${MAC}"
/bin/sleep 90
/sbin/reboot

Call it via cron (In Administration --> Management) like so:

0 0 * * 1,5 root /bin/sh /tmp/custom.sh

Make sure once you've saved the cronjob in the gui, you check to make sure it's actually configured in the file system:

cat /etc/cron.d/cron_jobs

Hope this helps someone. Thanks for the randomized MAC address code.

OwN
  • 187
  • 3
  • 14