Skip to content

Instantly share code, notes, and snippets.

@LanceMcCarthy
Created January 6, 2021 21:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LanceMcCarthy/6efd13c87d33567a7ec2bf5c067fab4e to your computer and use it in GitHub Desktop.
Save LanceMcCarthy/6efd13c87d33567a7ec2bf5c067fab4e to your computer and use it in GitHub Desktop.
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

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