What's new

DDNS custom script for use with asus.com

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Leechpool

Occasional Visitor
Hi,
Would it be possible to create a custom DDNS script that would operate with the free asus ddns service? My asus merlin router is subject to double NAT and I wondered if it were possible to still use asus ddns via a custom script. I've searched but not been able to find anything....
thanks
:)
 
I really appreciate the replies. I went with the script in the link Dabombber provided. It was great in terms of showing what was possible and the syntax required. I had to modify it because on the Asus merlin, the DDNS custom script is triggered when the WAN ip changes but it won't in a double NATed scenario. There is a forced interval setting but the most frequent is 1 day....I used the custom script to launched a script (if it wasn't already running) which periodically checked the external ip every 5 mins, updating if it had changed and updating even if it hadn't every week.....my bash skills are limited by I got there. Couldn't have done it with out the help above...thanks again.
:)
 
Could u post the script here? im facing similar issue https://www.snbforums.com/threads/vpn-few-questions-about-ip-address-logs-policy.40509/#post-341763:
I have few ports open from my provider as im on Local network with non-public IP
I got assigned few PORTs lets say 8000-8005 and can be used as "port.provider.com:8000" format to get into my devices from internet.
Everything works, but soon as i attach my IP NAS (unraid) and redirect traffic to VPN i lose the visibility to those ports/webui/services.
NAS act also as server and it has multiple services on it.

I need to use it for "port.provider.com:8000" and also DDNS solution for my FTP server as the VPN IP changes time to time. thx
 
Hi,
My scripts are as follows (remember my coding is not the best but it works for me...).

The following script is the one run by asus custom ddns. It checks script below (ddns_loop.sh) is running and runs it if it isn't

admin@RT-AC88U-97F8:/jffs/scripts# cat ./ddns-start
Code:
#!/bin/sh

# check if script is running. if not run it.

pidof "ddns_loop.sh" > /dev/null 2>&1

if [ $? -eq 0 ]; then
    /sbin/ddns_custom_updated 1
else
    /sbin/ddns_custom_updated 0
    /jffs/scripts/ddns_loop.sh &
fi

exit

The following is a script on asus which runs in a timing loop periodically forcing an update (weekly) and checking whether one is needed in between (every 5 mins)...NOTE YOU'LL NEED TO RUN THE FINAL SCRIPT IN REGISTER MODE FIRST AND UPDATE THE SCRIPT BELOW WITH MAC ADDRESS vice XX:XX......., YOURPASSWORD and YOURUSERNAME. where YOURPASSWORD is all numbers and YOURUSERNAME is your domain name i.e the bit in front of XXXXX.asuscomm.com

admin@RT-AC88U-97F8:/jffs/scripts# cat ./ddns_loop.sh

Code:
#!/bin/sh
while true
do
# change silent to console and run in ssh terminal to see what's happening
/jffs/scripts/ASUSddns2.sh XX:XX:XX:XX:XX:XX YOURPASSWORD YOURUSERNAME update silent forced
    x=1
    while [ $x -le 2016 ]    # 2016 x 5 mins = weekly
    do
      sleep 300   # 5 mins check if required
#      echo "Welcome $x times"
      /jffs/scripts/ASUSddns2.sh XX:XX:XX:XX:XX:XX YOURPASSWORD YOURUSERNAME update silent notforced
      x=$(( $x + 1 ))
    done
done
exit

For the final script, I took the script at https://github.com/BigNerd95/ASUSddns and modified it so you could force the update. Without this the script would not run when you want it to because the custom ddns script thing in asus router was looking at WAN ip to see when it needed to run.


admin@RT-AC88U-97F8:/jffs/scripts# ls
ASUSddns2.sh ddns-start ddns_loop.sh
admin@RT-AC88U-97F8:/jffs/scripts# cat ASUSddns2.sh

Code:
#!/bin/sh
# I added another parameter to end of function..if you put forced on end it will update the server with ip anyway...

asus_request(){
    case $mode in
        "register")
            local path="ddns/register.jsp"
            ;;
        "update")
            local path="ddns/update.jsp"
            ;;
    esac
    local password=$(calculate_password)
    echo $(curl --write-out %{http_code} --silent --output /dev/null --user-agent "ez-update-3.0.11b5 unknown [] (by Angus Mackay)" --basic --user $user:$password "[URL]http://ns1.asuscomm.com/$path?hostname=$host&myip=$wanIP[/URL]")

if [ $? -eq 0 ]; then
    /sbin/ddns_custom_updated 1
else
    /sbin/ddns_custom_updated 0
fi

}

calculate_password(){
    local stripped_host=$(strip_dots_colons $host)
    local stripped_wanIP=$(strip_dots_colons $wanIP)
    echo $(echo -n "$stripped_host$stripped_wanIP" | openssl md5 -hmac "$key" 2>/dev/null | cut -d ' ' -f 2 | tr 'a-z' 'A-Z')
}

get_wan_ip(){
    echo $(curl --silent [URL]http://api.ipify.org/[/URL])
    #echo $(ifconfig -a $(nvram get pppoe_ifname) 2>/dev/null | grep 'inet addr' | cut -d ':' -f 2 | cut -d ' ' -f 1)
}

is_dns_updated(){
    local dns_resolution=$(nslookup $host ns1.asuscomm.com 2>/dev/null)
    # check if wanIP is in nslookup result
    if [ $rogerforced = $rogercheck ]
    then
            return 1 # update is forced
    fi

    for token in $dns_resolution
    do
        if [ $token = $wanIP ]
        then
            return 0 # true
        fi
    done
    return 1 # false
}

code_to_string(){
    case $mode in
        "register")
            local log_mode="Registration"
            ;;
        "update")
            local log_mode="Update"
            ;;
    esac

    case $1 in
        200 )
            echo "$log_mode success."
            ;;
        203 | 233 )
            echo "$log_mode failed."
            ;;
        220 )
            echo "$log_mode same domain success."
            ;;
        230 )
            echo "$log_mode new domain success."
            ;;
        297 )
            echo "Invalid hostname."
            ;;
        298 )
            echo "Invalid domain name."
            ;;
        299 )
            echo "Invalid IP format."
            ;;
        401 )
            echo "Authentication failure."
            ;;
        407 )
            echo "Proxy authentication Required."
            ;;
        * )
            echo "Unknown result code. ($1)"
            ;;
    esac
}

strip_dots_colons(){
    echo $(echo "$1" | tr -d .:)
}

log(){
    case $output in
        "logger")
            logger -t "ASUSddns" "$1"
            ;;
        "silent")
            ;;
        *)
            echo "$1" >&2
            ;;
    esac
}

main(){
    case $mode in
        "register")
            ;;
        "update")
            if is_dns_updated
            then
                log "Domain already updated."
                return
            fi
            ;;
        *)
            log "Unknown action! Allowed action: register or update"
            return
            ;;
    esac

    local return_code=$(asus_request)
    local res=$(code_to_string $return_code)
    log "$res"
}

usage(){
    echo "Usage: mac wps host (register|update) (logger|console|silent)"
    echo
    echo "mac format: 00:11:22:33:44:55     (asus mac address) [to get it from nvram: nvram get et0macaddr]"
    echo "wps format: 12345678              (your wps code) [to get it from nvram: nvram get secret_code]"
    echo "host format: testestest           (your hostname without .asucomm.com)"
    echo
    echo "Program output:"
    echo "logger   -->  /var/log/messges"
    echo "console  -->  console"
    echo "silent   -->  mute output"
    echo
    echo "example to register and update testestest.asuscomm.com:"
    echo "$0 00:11:22:33:44:55 12345678 testestest register console"
    echo "$0 00:11:22:33:44:55 12345678 testestest update logger"
    echo
    echo "Launch 'register' the first time to register the new domain with your mac address."
    echo "Launch 'update' each 5 minutes (eg: with cron jobs) to keep dns updated."
    echo
    echo "ASUSddns script by BigNerd95 ([URL]https://github.com/BigNerd95/ASUSddns[/URL])"
}

if [ $# -eq 6 ]
then
    user=$(strip_dots_colons $1)
    key=$2
    host="$3.asuscomm.com"
    mode=$4
    output=$5
    rogerforced=$6
    rogercheck="forced"
    wanIP=$(get_wan_ip)
    if [ -n "${wanIP}" ]
    then
        main
    else
        log "No internet connection, cannot check."
    fi
else
    usage
fi
 
Last edited:
# this smiley face needs to be colon close bracket but I don't know how to stop this forum changing it.

Try to use the [ code ] and [ /code ] tags (without the spaces) before and after each piece of script. Without the slash at the beginning and with the slash after it. You can also use the editor: when you choose to edit your message, select each piece of code, choose the insert icon (to the right of the media (filmstrip) icon) and select code while the text is selected. It will put the correct tags in place and makes copying for others a whole lot easier.
 
Thanks MarCoMLXXV,
I've edited the post with the code in....I knew there was a way to do it but couldn't quickly work it out in the time I had earlier...
 
Hello,

Thanks for the script i finally kicked by self to do it ;)

I have few more confirm questions:

1. Do i need to register somewhere in Asus.com to get the DDNS name/pass? What i found i shouldnt...
I assume if here (http://iplookup.asus.com/nslookup.php) is not resolved found then i can use the name?
2. Can i use different DDNS providers with the same script?
3. Do i need to enable something in Router UI - WAN - DDNS
Yes i do: https://github.com/RMerl/asuswrt-merlin/wiki/Custom-DDNS
4. Those *.sh files needs to be copied into "/jffs/scripts" on Router and also make them "x" to be executable?
Yes i do

Edit: found some answers

Thanks
 
Last edited:
Asus uses your router's MAC for authentication, so as long it's an Asus router, it should automatically authenticate with them. It's also why changing to a new router wont allow you to reuse the old hostname, unless you free it first.

You can have multiple providers in your script if you wish. Have the ddns_updated call only run if the one you consider your most important DDNS service has succesfully registered.

Another thing worth considering if you use multiple DDNS providers is DNS-o-Matic.
 
i have AC88U and i want to run DDNS for VPN (as thats the only way to get PublicIP for me)

I just want to use one DDNS provider which is working(no preference)...tried by the instructions but i get error in main page : DDNS: MyName.asuscomm.com - Request error, try again!
In system log:

Oct 23 22:20:29 watchdog: start ddns.
Oct 23 22:20:29 rc_service: watchdog 560:notify_rc start_ddns

----
Not sure where is the problem or what to check

thanks
 
Try a different hostname with the asuscomm.com DDNS - maybe the one you chose is already in use.
 
I assume if i get such result http://iplookup.asus.com/nslookup.php its free

upload_2017-10-23_23-45-36.png

How is it with password? is just type anything?
Code:
#!/bin/sh
while true
do
# change silent to console and run in ssh terminal to see what's happening
/jffs/scripts/ASUSddns2.sh XX:XX:XX:XX:XX:XX password1 mytest12 update silent forced
    x=1
    while [ $x -le 2016 ]    # 2016 x 5 mins = weekly
    do
      sleep 300   # 5 mins check if required
#      echo "Welcome $x times"
      /jffs/scripts/ASUSddns2.sh XX:XX:XX:XX:XX:XX password1 mytest12 update silent notforced
      x=$(( $x + 1 ))
    done
done
exit

MAC i found with "ip link show" command
took mac from :
Code:
7: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc htb state UNKNOWN mode DEFAULT qlen 1000
    link/ether XX:XX:XX:XX:XX:XX brd ff:ff:ff:ff:ff:ff
 
killeriq,
Sorry it's a long time since I got this working so I can't easily answer your questions.
As the sentence in capital letters says in my post above...yes you need to use the script in register mode first to register with the asus server. Register mode, performs the necessary registration....you do not have to go to the site in a browser to do it.

The XX:XX:XX:XX:XX:XX in the script is the mac address...you get this by running a command on the asus.
The script ASUSddns2.sh contains this line in the usage output bit:
echo "mac format: 00:11:22:33:44:55 (asus mac address) [to get it from nvram: nvram get et0macaddr]"
Note the comments in various posts discussing this subject that some (and I) had to use a different addr e.g.: "nvram get et2macaddr" for this to work.
(I have confirmed that running nvram get et2macaddr on the asus returns the mac addressed used successfully in my script)

Your PASSWORD....this again comes from running code on the asus....try finding the notes in the script or reading the detail on the github link which says the following:
Wps pin code, it is used to calculate the password.
To get it, launch:
nvram get secret_code
(I have confirmed that running nvram get secret_code returns the PASSWORD used successfully in my script)

The only degree of freedom you have is the domain name i.e. host (the others came from running code on the Asus). This you are free to use what you want (assuming it's free i.e. not in use at Asus). I used a domain name I have actually registered and owned, so it was unlikely to be in use at Asus.

I suggest you try to get ASUSddns2.sh working via direct commands on the asus first i.e. use it to register, then use it to update. Once you have achieved this you can move on to using the other scripts to automate the update....

Hope this helps,
:)
 
Last edited:
Hello, thanks for you reply

Seems have it wrong as ive didnt check the https://github.com/BigNerd95/ASUSddns link , just edited and added your scripts into "/jffs/scripts/" rebooted and though it will work...:D

So i went again:

1. go to https://github.com/BigNerd95/ASUSddns
2. connected via SSH to router
started this:
curl https://raw.githubusercontent.com/BigNerd95/ASUSddns/master/ASUSddns.sh -O -k
chmod 777 ASUSddns.sh
3. run "nvram get et2macaddr" to get my MAC, et0 was giving 00:00....
4. run "nvram get secret_code" to get my code
5. run in ASUS "/jffs/scripts/"
upload_2017-10-28_18-58-37.png

didnt work: ./ASUSddns2.sh 00:11:22:33:44:55 11111111 teste register console

-sh: ./ASUSddns.sh: not found
5.1
run "sh ASUSddns2.sh 00:11:22:33:44:55 11111111 teste register console"

: not foundh: line 3:
ASUSddns2.sh: line 5: syntax error: unexpected word (expecting "in")

upload_2017-10-28_18-54-59.png


So i assume we are getting there slowly :)

EDIT:

With this script "ASUSddns.sh" i was able to register, with "ASUSddns2.sh is not working, no clue why:

killer@RT-AC88U-98B8:/jffs/scripts# ./ASUSddns2.sh
-sh: ./ASUSddns2.sh: not found
killer@RT-AC88U-98B8:/jffs/scripts# ./ASUSddns.sh XX 11 test register console
Registration success.
 

Attachments

  • ASUSddns2.txt
    4.6 KB · Views: 469
Last edited:
Hello, thanks for you reply

Seems have it wrong as ive didnt check the https://github.com/BigNerd95/ASUSddns link , just edited and added your scripts into "/jffs/scripts/" rebooted and though it will work...:D

So i went again:

1. go to https://github.com/BigNerd95/ASUSddns
2. connected via SSH to router
started this:
curl https://raw.githubusercontent.com/BigNerd95/ASUSddns/master/ASUSddns.sh -O -k
chmod 777 ASUSddns.sh
3. run "nvram get et2macaddr" to get my MAC, et0 was giving 00:00....
4. run "nvram get secret_code" to get my code
5. run in ASUS "/jffs/scripts/"
View attachment 10809
didnt work: ./ASUSddns2.sh 00:11:22:33:44:55 11111111 teste register console

-sh: ./ASUSddns.sh: not found
5.1
run "sh ASUSddns2.sh 00:11:22:33:44:55 11111111 teste register console"

: not foundh: line 3:
ASUSddns2.sh: line 5: syntax error: unexpected word (expecting "in")

View attachment 10807

So i assume we are getting there slowly :)

EDIT:

With this script "ASUSddns.sh" i was able to register, with "ASUSddns2.sh is not working, no clue why:

killer@RT-AC88U-98B8:/jffs/scripts# ./ASUSddns2.sh
-sh: ./ASUSddns2.sh: not found
killer@RT-AC88U-98B8:/jffs/scripts# ./ASUSddns.sh XX 11 test register console
Registration success.
This script is for DD-WRT firmware and a cursory look at it tells me it will not work with Asuswrt-Merlin without modifying it.
 
thelonelycoder, your name suggests you know way more about coding than I do....The only thing I'd say is I'm running merlin and it works ok...at least the update part does...it's possible I registered with the unaltered script....then created my modified script to automate the update...not realising I'd broken the registration part somehow.
Killeriq...now that you are registered and know what mac, password, host to use....I'd try running the modified script in update mode.
:)
 
ok but all the time i try to run yours i get:

killer@RT-AC88U-98B8:/jffs/scripts# ./ASUSddns2.sh
-sh: ./ASUSddns2.sh: not found

Even the file is there and i set 777 on it

See:
upload_2017-10-28_20-4-17.png


Question is what to do now:

1. just modify the "ddns_loop.sh" file with MAC,PASSWORD,Host and reboot router?
2. or do i need to run something in terminal

Linux is not my native OS so it doesnt make much sense why one works and other not
 

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top