Skip to content

Instantly share code, notes, and snippets.

@HighLibrarian
Created November 28, 2024 13:48
Show Gist options
  • Save HighLibrarian/05d191e7c2abca12f0a9a7e3da79185b to your computer and use it in GitHub Desktop.
Save HighLibrarian/05d191e7c2abca12f0a9a7e3da79185b to your computer and use it in GitHub Desktop.
GoDaddy update DNS
<#
This script is used to check and update your GoDaddy DNS server to the IP address of your current internet connection.
First go to GoDaddy developer site to create a developer account and get your key and secret
https://developer.godaddy.com/getstarted
Update the first 4 varriables with your information
#>
$domain = '' # your domain
$key = '' #key for godaddy developer API
$secret = '' #Secret for godday developer API
$names =@(
"hass"
)
$headers = @{}
$headers["Authorization"] = 'sso-key ' + $key + ':' + $secret
foreach ($name in $names)
{
$result = Invoke-WebRequest https://api.godaddy.com/v1/domains/$domain/records/A/$name -method get -headers $headers
$content = ConvertFrom-Json $result.content
$dnsIp = $content.data
# Get public ip address there are several websites that can do this.
$currentIp = Invoke-RestMethod http://ipinfo.io/json | Select-Object -ExpandProperty ip
if ( $currentIp -ne $dnsIp) {
$Request = @(@{ttl=3600;data=$currentIp; })
$JSON = Convertto-Json $request
Invoke-WebRequest https://api.godaddy.com/v1/domains/$domain/records/A/$name -method put -headers $headers -Body $json -ContentType "application/json"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment