forked from awslabs/route53-dynamic-dns-with-lambda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdynamic_dns_lambda_client.ps1
33 lines (25 loc) · 1.27 KB
/
dynamic_dns_lambda_client.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
#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
#
Param(
[Parameter(Mandatory=$True,Position=1)][string]$myHostname,
[Parameter(Mandatory=$True,Position=2)][string]$mySharedSecret,
[Parameter(Mandatory=$True,Position=3)][string]$myAPIURL)
$helptext = 'The script requires hostname and shared secret arguments
ie: dynamic_dns_lambda_client.ps1 host1.dyn.example.com. sharedsecret "abc123.execute-api.us-west-2.amazonaws.com/prod"'
$helptext
$getURL = $myAPIURL + "?mode=get"
$webRequest = Invoke-WebRequest -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
$webRequest = Invoke-WebRequest -URI $setURL
$webRequest.Content