DynDNS Monthly Login Script for TomatoUSB

DynDNS.org (Dyn) changed their free hostname(s) policy – accounts using free hostname(s) need to manually log in to their accounts every month (or 30 days) to prevent their hostname(s) from expiring and being deleted. Using an update client will no longer suffice. To workaround tackle this limitation, I have put together a script to automate the DynDNS monthly login. In fact, this automated script performs DynDNS login every week.
Requirements
- TomatoUSB-enabled router like ASUS RT-N66U, RT-N16, Linksys E4200. ASUS RT-AC66U.
- Flashed to TomatoUSB firmware (I am using TomatoUSB on my RT-N66U and RT-AC66U).
- Curl binary for TomatoUSB
- Geeky mind to do some troubleshooting
Setting up curl’s URL
The TomatoUSB firmware does not come with curl binary required for this DynDNS monthly login script to work. Hence, we will need to place the curl binary on a accessible location (preferably web host / Dropbox) to allow the TomatoUSB router retrieve it when required.
Note: This DynDNS monthly auto login script requires curl to work. This script makes use of wget to download curl from the URL. The wget on TomatoUSB does not support https URL.
For this guide, we will use dropbox to distribute the curl binary required for the script. You can also place it on your web host (if you have one).
- Download Curl binary for TomatoUSB.
- Unpack the package and upload it to your webhost or the public folder of your Dropbox.
- Note down the public link / URL to the location of curl on your webhost or Dropbox without the https (e.g. http://dl.dropbox.com/u/curl).
Inserting the DynDNS Monthly Login Script
- Using a web browser, login to the TomatoUSB web administration page.
- Navigate to Administration -> Scripts -> WAN Up tab. If the WAN Up tab has been used for AdBlock for TomatoUSB, you can use the Init tab instead.
- Copy and paste the contents below into the text area.
- Update the contents of both USERNAME and PASSWORD (line 13 and 14) with the details of your DynDNS account.
- Update the content of CURL_URL (line 17) with the public link / URL to the location of curl (step 3 from previous section).
- Save and reboot the router.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | ## DynDNS Auto Login Script ## www.shadowandy.net ## Version 1.0 sleep 60 DDNSAL="/tmp/DDNS_LOGIN.sh" { cat <<'ENDF' >$DDNSAL #!/bin/sh # DynDNS User Account USERNAME="username" PASSWORD="password" # Location of curl binary CURL_URL="http://example.com/curl" CURL_EXE="/tmp/curl" # User Agent to use USERAGENT="Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36" #### DO NOT EDIT BELOW #### if [[ ! -x $CURL_EXE ]]; then wget -O $CURL_EXE $CURL_URL chmod +x $CURL_EXE fi COOKIE="/tmp/DDNSAL.cookie" OUTPUT="/tmp/DDNSAL.output" MULTIFORM=`$CURL_EXE -s -k -A $USERAGENT -c $COOKIE https://account.dyn.com \ | awk -F\' '/multiform/{ print $6 }'` $CURL_EXE -s -k --location -A "$USERAGENT" -b $COOKIE -c $COOKIE -o $OUTPUT \--data "username=$USERNAME&password=$PASSWORD&iov_id=&submit=Log+in&multiform=$MULTIFORM" \https://account.dyn.com/ if grep -E "(Welcome|Hi).*$USERNAME" $OUTPUT > /dev/null 2>&1; then logger DDNS_AUTOLOGIN - Login Successful else logger DDNS_AUTOLOGIN - Login Unsuccessful FAILED="true" fi rm $COOKIE rm $OUTPUT if [ "$FAILED" = "true" ]; then exit 1 fi ENDF } chmod 755 $DDNSAL # Creating a crontab entry to login every Sunday at 2305 hrs if [[ "$(cru l | grep DDNSAL | cut -d '#' -f2)" != "DDNSAL" ]] ; then cru a DDNSAL "5 23 * * 0 $DDNSAL" fi $DDNSAL |
Verifying the script is running
- After the TomatoUSB router has rebooted, ssh into the router.
- Verify that DDNS_LOGIN.sh is created by typing “ls /tmp” without the quotes.
- Verify that the DDNS_LOGIN script is running by typing “cat /var/log/messages | grep DDNS_AUTOLOGIN” without the quotes.
It should show that the login was successful or unsuccessful - Congratulations! The DynDNS monthly login script is running!
Understanding the DynDNS Auto Login Script
DynDNS Account Details
The DynDNS account details are captured by the following variables. Do ensure the account information are correct.
1 2 3 | # DynDNS User Account USERNAME="username" PASSWORD="password" |
curl for TomatoUSB
Curl is not available on TomatoUSB. In this script, we are using curl to do the HTML form post for the DynDNS login. To make curl available on the TomatoUSB router, we will place the curl binary on a web accessible URL and have the script download it when required. The curl binary is placed in /tmp and will be gone after a power cycle.
1 2 3 | # Location of curl binary CURL_URL="http://example.com/curl" CURL_EXE="/tmp/curl" |
User Agent
We will want DynDNS to think that we are logging in to DynDNS manually. Hence, we will need to masquerade as a web browser. In this script, the user-agent is set to Chrome. For the geeks, you can freely change the content of this variable to reflect the user-agent that you like to spoof / masquerade.
1 2 | # User Agent to use USERAGENT="Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36" |
Running the script every Sunday 2305 hrs
The script runs automatically every Sunday at 2305 hrs. For the geeks, this is a cron entry through cru so you can freely change the frequency or the time it executes the DynDNS auto log in to your preference.
1 2 3 4 | # Creating a crontab entry to login every Sunday at 2305 hrs if [[ "$(cru l | grep DDNSAL | cut -d '#' -f2)" != "DDNSAL" ]] ; then cru a DDNSAL "5 23 * * 0 $DDNSAL" fi |