Last active
May 23, 2019 18:22
-
-
Save l0cutis/0c0d4d4bb710ef3da7547927abfe4e57 to your computer and use it in GitHub Desktop.
Dynamic DNS Update for Hover in PowerShell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Find your dnsID by browsing to | |
# https://www.hover.com/api/domains/YOURDOMAIN.com/dns | |
#Update which Hover record? | |
$dnsID = "dns12345678" | |
$dnsdomain = "YOURDOMAIN.com" | |
$username = "Username" | |
$password = "Password" | |
#Get current public IP (pretty cool little trick, don't adjust this line) | |
$myIP = Resolve-DnsName -Name myip.opendns.com -Server resolver1.opendns.com | |
#Connect to HoverAPI | |
$Headers = @{ "accept"="application/json"; | |
"content-type"="application/json"} | |
$params = @{ "username"=$username; | |
"password"=$password} | |
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 | |
$loginResult = Invoke-WebRequest -Uri "https://www.hover.com/api/login" -Method POST -Body ($params|ConvertTo-Json) -Headers $Headers -SessionVariable WebSession | |
#Check the login was successful | |
if($loginResult.Headers.'Set-Cookie' -notmatch "hoverauth" -or $loginResult.StatusDescription -ne "OK") | |
{ | |
Write-Host "There has been a problem" | |
} | |
else | |
{ | |
#update the record | |
$jsonRequest = '{"domain":{"id":"domain-' + $dnsdomain + '","dns_records":[{"id":"'+$dnsID+'"}]},"fields":{"content":"' + $myIP.IPAddress + '"}}' | |
$updateResult = Invoke-WebRequest -Uri "https://www.hover.com/api/control_panel/dns" -Method put -Body $jsonRequest -WebSession $WebSession | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment