jeudi 7 février 2013

How to fix Synology DDNS update (with No-IP)

Synology NAS are accessible from the outside using DDNS server, but their client apparently fails to update public IP changes when standing behind a NAT router (which is the common case for home usage, unless you're lucky enough to have an IPv6 ISP).

So what could I do? After not finding a solution, needing one and still loving my NAS, I wrote my own update script in Python.
To run it at startup: http://www.debian-administration.org/articles/28

Enjoy:


# Update my dynamic IP address on No-IP.org

import urllib2
import time
from datetime import datetime

URL = 'http://dynupdate.no-ip.com/nic/update?hostname=homebj.no-ip.org'
useragent = 'Synology DDNS bugfixer/1.0 your_email_noip@canazzi.com'
username = 'your_noip_username'
password = 'your_noip_password'

while 1:

    try:
        passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
        passman.add_password(None, URL, username, password)
        authhandler = urllib2.HTTPBasicAuthHandler(passman)
        opener = urllib2.build_opener(authhandler)
        opener.addheaders = [('User-agent', useragent)]
        urllib2.install_opener(opener)
        pagehandle = urllib2.urlopen(URL)

        reply_good = pagehandle.read()
        pagehandle.close()

        print datetime.now(), ":", reply_good

        # every hour: update!
        time.sleep(3600)
       
    except:
        print datetime.now(), ":", "Failed to update IP! "
        time.sleep(300)


Aucun commentaire: