What error are you getting? What response do you get from the web site?
Is $myIP correct? Display the contents of the $url variable before you call invoke-webrequest. Display the contents of the $update variable after the call.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi, I'm trying to develope a PowerShell script for a dynamic update service on Hurricane Electric service (aka HEnet) on IPv6 AAAA records. I have problems with the Invoke-WebRequest when applying the update, don't know what I'm doing wrong here.
This is my code:
# Set static content
$myPass = "thepassword"
$myHost = "thedyn.domain.com"
$myWan = "Ethernet"
#Write-Eventlog -Logname 'Application' -Source 'HEnet Updater' -EventID 666 -EntryType Information -Message "Starting…"
# Fetch external IP
Write-Host "Fetching external IP..."
$response = Get-NetIPAddress -AddressFamily IPv6 -InterfaceAlias "$myWan" -SuffixOrigin "Link" -PrefixOrigin "RouterAdvertisement"
$myIP = $response.IPAddress.Trim()
Write-Host "Value $myIP found, validating..."
# Validating IP
$IPCheck = [bool]("$myIP" -as [ipaddress])
Write-Host "Validation result: $IPCheck $myIP"
If ($IPCheck -eq $false)
{
Write-Host "Failed to get external IP. Trying with external method."
$myIP = (Invoke-WebRequest -Uri "http://checkipv6.dyndns.com").Content -replace "(<html><head><title>Current IP Check</title></head><body>Current IP Address: )|(</body></html>)|",""
Write-Host "Value $myIP found, assuming as external IP."
Exit
}
Write-Host "External IP: $myIP"
# Build URL for update
$URL = "http://${myHost}:${myPass}@dyn.dns.he.net/nic/update?hostname=$myHost&myip=$myIP"
# Print output
Write-Host "Updating host $myHost with IP $myIP"
# Updated
$update = Invoke-WebRequest $URL
# Write to EventLog
$strToLog = "Error returned: $update'r'nFull HTTPS string used: $URL"
Write-Host "Writing to log: $strToLog"
#Write-Eventlog -Logname 'Application' -Source 'No-IP Updater' -EventID 666 -EntryType Information -Message $strToLog
What error are you getting? What response do you get from the web site?
Is $myIP correct? Display the contents of the $url variable before you call invoke-webrequest. Display the contents of the $update variable after the call.
Hi @MotoX80 , thanks for answering!
Yes $myIP is correct, its a IPv6 address and the outpu in this case is 2xxx:xxxx:xxxx:xxxx:b4e7:4193:4d0c:914b also the script does run a validation on:
$IPCheck = [bool]("$myIP" -as [ipaddress])
Write-Host "Validation result: $IPCheck $myIP"
The $url content is: http://thedyn.domain.com:thepassword[@](/users/na/?userId=9caf6c8e-0000-0003-0000-000000000000).dns.he.net/nic/update?hostname=thedyn.domain.com&myip=2xxx:xxxx:xxxx:xxxx:b4e7:4193:4d0c:914b
As described by dns.he.net website, also if you use this address on a browser it does work.
The result after invoking that address is:
Invoke-WebRequest : El servidor ha cometido una infracción de protocolo. Section=ResponseStatusLine
En C:\Users\Usuario\noip.ps1: 45 Carácter: 11
Try changing the URL to HTTPS.
# Build URL for update
$URL = "https://${myHost}:${myPass}@dyn.dns.he.net/nic/update?hostname=$myHost&myip=$myIP"
Hi, I have already tryed that.
Also by replacing the line with:
Even in each case, with http or https.
So, I was able to figure it out in some way, with Wireshark as @Rich Matheisen said I was able to capture the packets, the problem is that the reponse from the server was: 401 Authorization Required
Even if I place the credentials on the $URL on the part http://${myHost}:${myPass}@ there is still some required step and that is to acept the connection with such credentials!
So what I did, Ive change the $URL for:
$URL = "http://dyn.dns.he.net/nic/update?hostname=${myHost}&password=${myPass}&myip=${myIP}"