forked from awslabs/route53-dynamic-dns-with-lambda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroute53-ddns-client-lite.ps1
37 lines (30 loc) · 1.52 KB
/
route53-ddns-client-lite.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
#Lite client. Does not support ipv6 or internal ip.
#PowerShell:
# to enable scripts to run, you need to change execution policy to allow 3rd party scripts to run.
# https://technet.microsoft.com/en-us/library/hh849812.aspx
# To launch a subshell to run the script, use:
# powershell –ExecutionPolicy Bypass
# Run as:
# .\route53-ddns-client-lite.ps1 -myHostname foo.example.com. -mySharedSecret sharedsecret
# -myAPIURL ddns.example.com -myAPIKEY apikey
Param(
[Parameter(Mandatory=$True,Position=1)][string]$myHostname,
[Parameter(Mandatory=$True,Position=2)][string]$mySharedSecret,
[Parameter(Mandatory=$True,Position=3)][string]$myAPIURL,
[Parameter(Mandatory=$True,Position=4)][string]$myAPIKEY)
# Add a trailing '.' if not submitted in argument
If (!($myHostname.EndsWith("."))){
$myHostname = "$myHostname."
}
$getURL = $myAPIURL + "?mode=get"
$webRequest = Invoke-WebRequest -Headers @{"x-api-key"="$myAPIKEY"} -URI $getURL
$myIP = $webRequest.Content.Replace('{"return_message": "', '').Replace('", "return_status": "success"}','')
$message = $myIP + $myHostname + $mySharedSecret
$sha256 = New-Object System.Text.StringBuilder
[System.Security.Cryptography.HashAlgorithm]::Create("SHA256").ComputeHash([System.Text.Encoding]::UTF8.GetBytes($message))|%{
[Void]$sha256.Append($_.ToString("x2"))
}
$message = $sha256.ToString()
$setURL = $myAPIURL + "?mode=set&hostname=" + $myHostname + "&hash=" + $message + "&internalIp=" + $myIp
$webRequest = Invoke-WebRequest -Headers @{"x-api-key"="$myAPIKEY"} -URI $setURL
$webRequest.Content