script for updating a google domain DDNS?

Posted on
Tue Feb 27, 2018 9:18 am
Professor Falken offline
User avatar
Posts: 289
Joined: Mar 29, 2015

script for updating a google domain DDNS?

Does anyone have a script or another method for updating a Google Domain DDNS from within Indigo? (Not sure if a phrased that exactly right, but you probably get what I mean).

My router doesn't support updating Google's DDNS, but that's where I own the names, and they do have DDNS support. I know there are some separate client programs that do this, but configuring them seems to be a bear. Since I have the Online Sensor plugin, and it checks my public IP anyway, I figured one easy work around could be to just let Indigo take over this function via a device state change trigger.

Maybe I'm thinking about this wrong and there are reasons not to do it this way, but figured someone on the board may have doe this before.

Thanks.

Posted on
Wed Feb 28, 2018 6:38 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: script for updating a google domain DDNS?

https://support.google.com/domains/answ ... 3?hl=en-GB

There’s a simple HTTP call that can be made with a two or three line script.


Sent from my iPhone using Tapatalk Pro

Posted on
Wed Feb 28, 2018 9:16 am
Professor Falken offline
User avatar
Posts: 289
Joined: Mar 29, 2015

Re: script for updating a google domain DDNS?

howartp wrote:
https://support.google.com/domains/answer/6147083?hl=en-GB

There’s a simple HTTP call that can be made with a two or three line script.


Sent from my iPhone using Tapatalk Pro



Yes, I saw that too, thanks. In fact, that's what made me think it would be scriptable within Indigo. The problem is, with my minuscule python abilities, I'm not exactly sure how to get my new IP (which will be a device state on the online checker plugin device) into the actual http call. Obviously substituting the domain and the generated credentials into their example call is easy, since that stuff doesn't change.

I also didn't really understand the second part of the description. It almost sounded like I needed to set up email on my domain, which I have no need for.

Code: Select all
Note: You must set a user agent in your request as well. Web browsers will generally add this for you when testing via the above url. In any case, the final HTTP request sent to our servers should look something like this:

Example HTTP query:
POST /nic/update?hostname=subdomain.yourdomain.com&myip=1.2.3.4 HTTP/1.1
Host: domains.google.com
Authorisation: Basic base64-encoded-auth-string User-Agent: Chrome/41.0 your_email@yourdomain.com



If it was just something I was messing around with at home, I'd keep playing with it until I got it to work. But I'm a little concerned about doing that with google, lest I get locked out of my account or something for sending too many wrongly formatted calls.

Posted on
Wed Feb 28, 2018 9:31 am
Colorado4Wheeler offline
User avatar
Posts: 2794
Joined: Jul 20, 2009
Location: Colorado

Re: script for updating a google domain DDNS?

Professor Falken wrote:
I'm not exactly sure how to get my new IP (which will be a device state on the online checker plugin device) into the actual http call.

It depends on which method you are using to make the call. Here is an example using the Online plugin's IP address state:

Code: Select all
import requests

onlineDev = 12345 # Address of actual Online IP device

url = "http://{}".format(unicode(indigo.devices[onlineDev].states["ipAddress"]))

data = {"[]"} # Any JSON data you might be passing

data_json = json.dumps(data)
payload = {'json_payload': data_json}
r = requests.get(url, data=payload)

My Modest Contributions to Indigo:

HomeKit Bridge | Device Extensions | Security Manager | LCD Creator | Room-O-Matic | Smart Dimmer | Scene Toggle | Powermiser | Homebridge Buddy

Check Them Out Here

Posted on
Wed Feb 28, 2018 11:05 am
Professor Falken offline
User avatar
Posts: 289
Joined: Mar 29, 2015

Re: script for updating a google domain DDNS?

Thanks. I'll see if I can run with that and make it work.

Posted on
Wed Feb 28, 2018 11:11 am
Colorado4Wheeler offline
User avatar
Posts: 2794
Joined: Jul 20, 2009
Location: Colorado

Re: script for updating a google domain DDNS?

If you copy and paste you'll get a missing JSON library, here's the corrected code:

Code: Select all
import requests, json

onlineDev = 12345 # Address of actual Online IP device

url = "http://{}".format(unicode(indigo.devices[onlineDev].states["ipAddress"]))

data = {"[]"} # Any JSON data you might be passing

data_json = json.dumps(data)
payload = {'json_payload': data_json}
r = requests.get(url, data=payload)

My Modest Contributions to Indigo:

HomeKit Bridge | Device Extensions | Security Manager | LCD Creator | Room-O-Matic | Smart Dimmer | Scene Toggle | Powermiser | Homebridge Buddy

Check Them Out Here

Posted on
Wed Feb 28, 2018 3:16 pm
Professor Falken offline
User avatar
Posts: 289
Joined: Mar 29, 2015

Re: script for updating a google domain DDNS?

Thanks again. I'm still trying to wrap my head around everything you've told me there and see where I'd need to put in my domain, username, and password.

However, I just noticed on a re-read of the Google Domains DDNS API, that if I just leave the myIP part of the call blank, the Google servers update the DNS record to the IP from which the call comes. Does that mean its as as simple as something like:

Code: Select all
import requests
url = "https://username:password@domains.google.com/nic/update?hostname=subdomain.yourdomain.com>"
requests.get(url)


Can Indigo send https requests like that? My only experience was with http calls from one machine to another on my own LAN.

Posted on
Wed Feb 28, 2018 3:22 pm
Colorado4Wheeler offline
User avatar
Posts: 2794
Joined: Jul 20, 2009
Location: Colorado

Re: script for updating a google domain DDNS?

Sure, of course, I was just posting one that came to mind. There are probably at least a dozen ways to call a URL from Python, my simply including sending JSON if you needed to.

My Modest Contributions to Indigo:

HomeKit Bridge | Device Extensions | Security Manager | LCD Creator | Room-O-Matic | Smart Dimmer | Scene Toggle | Powermiser | Homebridge Buddy

Check Them Out Here

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 0 guests