-
Notifications
You must be signed in to change notification settings - Fork 25
/
Update-DuckDNS.ps1
executable file
·69 lines (58 loc) · 1.67 KB
/
Update-DuckDNS.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#Requires -Version 2
<#
.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
.LINK
https://github.com/ataylor32/duckdns-powershell
#>
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..."
If ($PSVersionTable.PSVersion.Major -Gt 2) {
$Result = Invoke-WebRequest $URL
If ($Result -Ne $Null) {
$ResponseString = $Result.ToString()
}
}
Else {
$Request = [System.Net.WebRequest]::Create($URL)
$Response = $Request.GetResponse()
If ($Response -Ne $Null) {
$StreamReader = New-Object System.IO.StreamReader $Response.GetResponseStream()
$ResponseString = $StreamReader.ReadToEnd()
}
}
If ($ResponseString -Eq "OK") {
Write-Verbose "Update successful."
}
ElseIf ($ResponseString -Eq "KO") {
Throw "Update failed."
}