Skip to content

Instantly share code, notes, and snippets.

@monaboiste
Created October 5, 2020 15:43
Show Gist options
  • Save monaboiste/2660dc59255b8f7212b10aa445ffd224 to your computer and use it in GitHub Desktop.
Save monaboiste/2660dc59255b8f7212b10aa445ffd224 to your computer and use it in GitHub Desktop.
Updates the IP address of your Duck DNS domain(s). Intended to be run as a scheduled task.
<#
.SYNOPSIS
Updates the IP address of your Duck DNS domain(s).
.DESCRIPTION
Updates the IP address of your Duck DNS domain(s). Intended to be run as a
scheduled task.
.PARAMETER Domains
A comma-separated list of your Duck DNS domains to update.
.PARAMETER Token
Your Duck DNS token.
.PARAMETER IP
The IP address to use. If you leave it blank, Duck DNS will detect your
gateway IP.
.INPUTS
None. You cannot pipe objects to this script.
.OUTPUTS
None. This script does not generate any output.
.EXAMPLE
.\Update-DuckDNS.ps1 -Domains "foo,bar" -Token my-duck-dns-token
#>
Param (
[Parameter(
Mandatory=$True,
HelpMessage="Comma separate the domains if you want to update more than one."
)]
[ValidateNotNullOrEmpty()]
[String]$Domains,
[Parameter(Mandatory=$True)]
[ValidateNotNullOrEmpty()]
[String]$Token,
[String]$IP
)
$URL = "https://www.duckdns.org/update?domains={0}&token={1}&ip={2}" -F $Domains, $Token, $IP
Write-Debug "`$URL set to $URL"
Write-Verbose "Sending update request to Duck DNS..."
$Result = Invoke-RestMethod $URL
If ($Result -Ne $Null) {
$ResponseString = $Result.ToString()
}
If ($ResponseString -Eq "OK") {
Write-Verbose "Update successful."
}
ElseIf ($ResponseString -Eq "KO") {
Throw "Update failed."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment