Not signed in (Sign In)
    • CommentAuthorfreakerz
    • CommentTimeAug 2nd 2008 edited
     permalink
    Hi,
    I'm trying to create a DDNS script, having my Tomato firmwared router go to a PHP page which calls a Python script to PUT the new IP address.

    The PHP file works, it seems to be on the Python side that I'm having issues.

    I had to build a custom pyactiveresource because line 108 sends a "params" global variable that did not exist, could this be the culprit? I didn't find info on that variable anywhere...

    IPUPDATE.PY — python ipupdate.py 66.123.12.52 12345:

    import urllib, re, sys, os
    from pyactiveresource import ActiveResource

    # ActiveResource Class for Slicehost DNS API
    class Record(ActiveResource):
    class Meta:
    api_key = '123123123'
    site = ''.join( ['https://', api_key, '@api.slicehost.com/'] );

    if len(sys.argv) == 3:
    record_id = sys.argv[2]
    else:
    print ''.join( ['Usage: ', sys.argv[2], ' recordID\n'] )
    sys.exit(1)

    results = Record.find(id=record_id)
    if len(results) != 1:
    print "Can't find Record " + record_id + " via SliceHost API."
    sys.exit(1)

    salon = results[0]
    found_ip = sys.argv[1]
    if salon.data != found_ip:
    salon.data = found_ip
    if not salon.save():
    print "IP Update failed, check logs."
    else:
    print "IP Updated: " + found_ip
    else:
    print "IP Unchanged: " + salon.data
    •  
      CommentAuthorSuperJared
    • CommentTimeAug 2nd 2008 edited
     permalink
    That was a stupid mistake on my part. I just uploaded pyactiveresource 0.2.6 0.2.7 which should work for you.
    • CommentAuthorfreakerz
    • CommentTimeAug 3rd 2008
     permalink
    Awesome!

    That did the trick, thank you very much for the quick fix. :)
    • CommentAuthorawox
    • CommentTimeJan 9th 2009
     permalink
    Working script for latest pyactiversource below.

    import urllib, re, sys, os
    from pyactiveresource.activeresource import ActiveResource

    api_key = 'xxxxxx'
    api_url = 'https://%s@api.slicehost.com/' % api_key
    record_id = '31337'

    class Record(ActiveResource):
    _site = api_url

    results = Record.find(id=record_id)
    if len(results) != 1:
    print "Can't find Record %s via SliceHost API." % record_id
    sys.exit(1)

    salon = results[0]
    found_ip = (re.findall('[0-9.]+', urllib.urlopen('http://checkip.dyndns.org/').read())[-1])
    if salon.data != found_ip:
    salon.data = found_ip
    salon.save()
    print "IP Updated: " + found_ip
    else:
    print "IP Unchanged: " + salon.data