Created
January 6, 2021 21:05
-
-
Save LanceMcCarthy/6efd13c87d33567a7ec2bf5c067fab4e to your computer and use it in GitHub Desktop.
GoDaddy DDNS Trick
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)`"}]" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can run this on a schedule by using the Windows Task Scheduler app.