-
-
Save cyrusboadway/5a7b715665f33c237996 to your computer and use it in GitHub Desktop.
#!/bin/bash | |
### Google Domains provides an API to update a DNS "Syntheitc record". This script | |
### updates a record with the script-runner's public IP, as resolved using a DNS | |
### lookup. | |
### | |
### Google Dynamic DNS: https://support.google.com/domains/answer/6147083 | |
### Synthetic Records: https://support.google.com/domains/answer/6069273 | |
USERNAME="" | |
PASSWORD="" | |
HOSTNAME="yoursubdomain.yourdomain.here" | |
# Resolve current public IP | |
IP=$( dig +short myip.opendns.com @resolver1.opendns.com ) | |
# Update Google DNS Record | |
URL="https://${USERNAME}:${PASSWORD}@domains.google.com/nic/update?hostname=${HOSTNAME}&myip=${IP}" | |
curl -s $URL |
I did something similar with python, avoiding calls from google domains. Today I have the script running every 5 minutes.
I'm getting badagent when trying to run in macosx terminal
Nevermind fixed it. Changed to use Google domains to get IP
only posting here because i was drawn in by the search engine... never transmit your username and password in anything but TLS and proper TLS... dont be a fool its not worth it in the end.
you can use this for ip address retrieval
currentipaddress="$(wget -q -O - checkip.dyndns.org | sed -e 's/.Current IP Address: //' -e 's/<.$//')"
or you can use this if you are directly connected... change to your correct network interface though
currentipaddress="$(ifconfig eth1 | grep -o "inet addr:([0-9]{1,3}.){3}[0-9]{1,3}" | sed 's/inet addr://')"
and this is the curl request that i have formed and it works perfectly everytime.
curloutput=$(curl -s --data-urlencode "hostname=@.domain.com" --data-urlencode "myip=$currentipaddress" -H "Host: domains.google.com" -u "$username:$password" "https://domains.google.com/nic/update")
echo "$curloutput" to wherever you want
I know this is an old thread but you can just send a request to the URL and not include the IP just pass the username and password.
The API will then use the IP the request was sent from.
e.g.
curl https://username:password@domains.google.com/nic/update?hostname=subdomain.yourdomain.com
For more details see the section at the bottom of this page labelled "Using the API to update your Dynamic DNS record"
https://support.google.com/domains/answer/6147083?hl=en-GB
I had to change line 15 to IP=$( curl ifconfig.me )
. Other than that the script works.
A stare is born
Does anyone know if there is an update to this to work with Squarespace since Google Domains has retired?
Squarespace does not offer an API for DNS configuration. There is no practical mechanism to programmatically manage dynamic DNS records for domains they manage.
Squarespace has a registrar & DNS business, independent of their hosting services: https://domains.squarespace.com
Squarespace purchased all Google Domains registrations: https://support.google.com/domains/answer/13689670
Any users whose domain registrations were transferred with the purchase would need to find a new registrar if they want a DDNS API.
I think it would be slightly more secure to do this so your username and password are not in plain text (url) provided you're making an HTTPS request:
curl --user ${USERNAME}:${PASSWORD} -s $URL