Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
GoDaddy DDNS Trick
Write-Output "$(Get-Date -Format 'u') Quick & Dirty DDNS"
# Go to https://developer.godaddy.com/ and get an API key + secret
$godaddy_api_key = ""
$godaddy_api_key_secret = ""
$godaddy_authorization = "sso-key $($godaddy_api_key):$($godaddy_api_key_secret)"
# We will be using the domans endpoint https://developer.godaddy.com/doc/endpoint/domains
# Lets say you want to update "wan.mydomain.com", the hostname is 'wan' and domain is 'mydomain.com'
$domain = "mydomain.com"
$hostname = "wan"
$request_uri = "https://api.godaddy.com/v1/domains/$($domain)/records/A/$($hostname)"
# Getting current external IP address
Write-Output "Checking WAN IP Address..."
$wan_ip = Invoke-RestMethod -Uri "https://api.ipify.org"
# Getting the DNS record IP address
Write-Output "Checking GoDaddy DNS Record..."
$dns_query_result = Invoke-RestMethod -Uri $request_uri -Headers @{ Authorization = $godaddy_authorization }
# Compare results
Write-Output "External IP: $($wan_ip), GoDaddy DNS IP: $($dns_query_result.data)"
If ($dns_query_result.data -eq $wan_ip) {
# If the IP addresses are identical, we're done.
Write-Output "[UNCHANGED] IP address has not changed, DNS update is not necessary."
}
else {
# If the IP address has changed, update the GoDaddy DNS record
Write-Output "[WAN IP CHANGED] The external IP address has changed. Updating $($hostname).$($domain) DNS record to $($wan_ip)."
Invoke-RestMethod -Method PUT -Uri $request_uri -Headers @{ Authorization = $godaddy_authorization } -ContentType "application/json" -Body "[{`"data`": `"$($myip)`"}]"
}
@LanceMcCarthy
Copy link
Author

LanceMcCarthy commented Jun 12, 2021

You can run this on a schedule by using the Windows Task Scheduler app.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment