Well, I didn't figure out how exactly to emulate clicking the Apply button on the WAN page (after changing the MAC Clone address). I tried various combinations of restarting the services listed in the log in my previous post (along with running
nvram commit) but never got the same results I got from manually clicking the Apply button.
However, I did manage to find a procedure that works well for changing my MAC Clone address (and subsequently my public IP address) via Telnet.
As mentioned above, I was having issues with variation in the amount of time it would take for my public IP to change. More often than not, it was taking around 140 seconds, instead of around 60 seconds as it should (as it always did when I would manually click the Apply button).
My best guess is that it was largely luck that I was achieving a 60-second delay at all when using the Telnet method mentioned above. It seems it was a timing issue. If the timing between running
nvram commit and cycling power on the modem was just right, I'd get around a 60-second delay, otherwise around 140 seconds. I suspect another factor was what sort of activity the router/and or modem were engaged in at that particular moment.
The key to getting approximately a 60-second delay every time turned out to be stopping and restarting the wan service in the following order:
- stop the wan service (
service stop_wan)
- cycle power on the modem
- change the value of the MAC address variable (eg,
nvram set wan0_hwaddr_x=12:34:56:78:90:AB)
- commit the change (
nvram commit)
- wait 55 seconds (for modem to start up)
- start the wan service (
service start_wan)
That process has worked flawlessly for me. I don't know how well it'll work for you though.
I'm using a Motorola SB6120 cable modem (and, as mentioned above, my router is an ASUS RT-N66U and my firmware is Merlin 378.56_2).
Note: As of writing this, I don't actually manually cycle the power on my modem anymore. I don't manually do anything actually. I now have a script that opens Telnet, logs me in and enters a single chain of commands that generates a random MAC and performs the steps listed above.
Below is the chain of commands I'm currently using. I'm new to Linux, and the command options are a bit limited on the router's version of Linux, so don't expect a thing of beauty. Use at your own peril, though you'll probably have no problems if you have the same hardware & firmware as me.
Code:
tImEs=$(date +%s);tImEp=0;pRvIP=$(nvram get wan0_ipaddr);cUrIP=$pRvIP;until [[ "$RdMaC" != "" && "$(nvram show|grep -i -q "$RdMaC";echo $?)" != "0" ]];do RdMaC=$(echo $(cat /dev/urandom| head -c 22)|md5sum|sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\)\(..\).*$/\1:\2:\3:\4:\5:\6/'|sed s/./$(expr substr 02468ACE $(grep -m1 -a -o '[1-8]' /dev/urandom|head -n1) 1)/2|tr 'a-z' 'A-Z' );usleep 100000;done;wget -b -q -O- http://192.168.100.1/reset.htm &> /dev/null;sleep 6;service stop_wan;clear;sleep 2;nvram set wan0_hwaddr_x=$RdMaC;nvram commit;clear;echo wait...;sleep 45;service start_wan;clear;echo -n wait...;until [[ "$cUrIP" != "$pRvIP" && "$cUrIP" != "0.0.0.0" && $(echo $cUrIP|grep -q "192.168.1";echo $?) != "0" ]] || [ $tImEp -gt 210 ];do cUrIP="$(nvram get wan0_ipaddr)";tImEp=$(( $(date +%s)-$tImEs ));sleep 1;echo -n .;done;clear;echo Previous IP: $pRvIP;echo Current IP: $cUrIP;echo Seconds waited: $tImEp;if [ $tImEp -gt 210 ];then echo -FAILED-;else echo -Success-;fi;unset tImEs tImEp cUrIP pRvIP RdMaC