Update my IP using DynDns in Python

1

I am verifying a small program to update my IP in DynDns.

What I do is the following:

#!/usr/bin/python
import requests
import json
user = "email"
password = "pass"
checkip = "http://thisisnt.com/api/getRemoteIp.php"
dynupdate = "https://members.dyndns.com/nic/update"
print "starting. Get current IP..."
ipraw = requests.get(checkip)
if ipraw.status_code is not 200:
  raise "Cannot get IP address"
  exit

ip = ipraw.json()['REMOTE_ADDR']
print "Remote IP: " + ip
print "updating..."
# update dyndns
headers = {'user-agent': 'mPythonClient/0.0.3'}
dyn = requests.get(dynupdate, \
              headers=headers, \
              auth=(user, password), \
              params={'hostname': 'xjhdshsdhagsafhg.ddns.net', \
                       'myip': ip, \
                       'wildcard': 'NOCHG', \
                       'mx': 'MX', \
                       })
if dyn.status_code is not 200:
  print "Update failed. HTTP Code: " + str(dyn.status_code)
if "good" in dyn.text:
  print "update successful.."
else:
  print "Update unsuccessful: " + dyn.text.strip()

I think I have put the data and the parameters correctly, but the problem is that when I run it the update is not successful:

My question is: how could I get back my correctly updated IP? Always stay in:

print "Update unsuccessful: " + dyn.text.strip()

And what I would like to do is to update it with the new IP and print it:

print "update successful.." + ip
    
asked by Sergio Ramos 13.03.2017 в 20:33
source

1 answer

1

As can be inferred from the error that the server returns when making the request ( badauth ), the problem is with the authentication method that you are using.

If you take a look at the Dyn documentation , you'll see that user use and password to authorize the requests has become obsolete , and therefore you have to use a updater client key (key for the updating client).

You can generate one of those keys from your account .

Once you have it, put that new key instead of pass :

password = "pass"

And change the API endpoint to the new one:

dynupdate = "https://members.dyndns.org/v3/update"

You can also delete the keys wildcard and mx of the dictionary params , since they are unnecessary.

Ready! When executing your script should work correctly. Remember to add the line you mention in your question, so that it shows the new IP as you want:

if "good" in dyn.text:
    print "Update successful... " + ip
    
answered by 22.06.2017 / 16:17
source