├── LICENSE.txt ├── README.md └── Update-DuckDNS.ps1 /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Adam Taylor and contributors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Update-DuckDNS.ps1 2 | 3 | Updates the IP address of your Duck DNS domain(s). Intended to be run as a scheduled task. 4 | 5 | ## Requirements 6 | 7 | 1. PowerShell 2.0+ 8 | 9 | ## Usage 10 | 11 | `.\Update-DuckDNS.ps1 -Domains "foo,bar" -Token my-duck-dns-token` 12 | 13 | ## Task Scheduler Instructions: 14 | 1. Open Task Scheduler: 15 | 1. Win+R (run): taskschd.msc 16 | 2. Right-click "Task Scheduler Library" and click "Add Basic Task" 17 | 1. Name it and set a schedule of "daily" 18 | 2. Action: Start a program 19 | 1. Program Script: powershell.exe 20 | 2. Add Arguments: -ExecutionPolicy ByPass -File "C:\Path\To\Powershell\Script\Update-DuckDNS.ps1" -Domains "foo,bar" -Token my-duck-dns-token 21 | 3. Finish 22 | 4. Go into settings and check the box for "Run task as soon as possible after a scheduled start is missed" 23 | 3. Test: 24 | 1. Login to DuckDNS's site and change your ip to something new manually 25 | 2. Right click the task in Task Scheduler and select "Run" 26 | 3. Verify your IP has been updated on DuckDNS site. -------------------------------------------------------------------------------- /Update-DuckDNS.ps1: -------------------------------------------------------------------------------- 1 | #Requires -Version 2 2 | 3 | <# 4 | .SYNOPSIS 5 | Updates the IP address of your Duck DNS domain(s). 6 | .DESCRIPTION 7 | Updates the IP address of your Duck DNS domain(s). Intended to be run as a 8 | scheduled task. 9 | .PARAMETER Domains 10 | A comma-separated list of your Duck DNS domains to update. 11 | .PARAMETER Token 12 | Your Duck DNS token. 13 | .PARAMETER IP 14 | The IP address to use. If you leave it blank, Duck DNS will detect your 15 | gateway IP. 16 | .INPUTS 17 | None. You cannot pipe objects to this script. 18 | .OUTPUTS 19 | None. This script does not generate any output. 20 | .EXAMPLE 21 | .\Update-DuckDNS.ps1 -Domains "foo,bar" -Token my-duck-dns-token 22 | .LINK 23 | https://github.com/ataylor32/duckdns-powershell 24 | #> 25 | 26 | Param ( 27 | [Parameter( 28 | Mandatory=$True, 29 | HelpMessage="Comma separate the domains if you want to update more than one." 30 | )] 31 | [ValidateNotNullOrEmpty()] 32 | [String]$Domains, 33 | 34 | [Parameter(Mandatory=$True)] 35 | [ValidateNotNullOrEmpty()] 36 | [String]$Token, 37 | 38 | [String]$IP 39 | ) 40 | 41 | $URL = "https://www.duckdns.org/update?domains={0}&token={1}&ip={2}" -F $Domains, $Token, $IP 42 | 43 | Write-Debug "`$URL set to $URL" 44 | 45 | Write-Verbose "Sending update request to Duck DNS..." 46 | 47 | If ($PSVersionTable.PSVersion.Major -Gt 2) { 48 | $Result = Invoke-WebRequest $URL 49 | 50 | If ($Result -Ne $Null) { 51 | $ResponseString = $Result.ToString() 52 | } 53 | } 54 | Else { 55 | $Request = [System.Net.WebRequest]::Create($URL) 56 | $Response = $Request.GetResponse() 57 | 58 | If ($Response -Ne $Null) { 59 | $StreamReader = New-Object System.IO.StreamReader $Response.GetResponseStream() 60 | $ResponseString = $StreamReader.ReadToEnd() 61 | } 62 | } 63 | 64 | If ($ResponseString -Eq "OK") { 65 | Write-Verbose "Update successful." 66 | } 67 | ElseIf ($ResponseString -Eq "KO") { 68 | Throw "Update failed." 69 | } 70 | --------------------------------------------------------------------------------