How do you update your dynamic IP address with a PowerShell script?

Use PowerShell to update your domain’s DNS dynamically with Loopia.

The script

#Your info goes here
$hostname = "yourdomain.com"
$user = "username"
$pwd = "password"

#Force TLS 1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

#Get a page with your current IP
$MyIpPage = Invoke-WebRequest "https://dyndns.loopia.se/checkip"

#Make sure we got a IP back in the response
If ($MyIpPage -match "(?:[0-9]{1,3}.){3}[0-9]{1,3}")
{
 $myIp = $Matches[0]

 #Create a set of credentials
 $secpasswd = ConvertTo-SecureString $pwd -AsPlainText -Force
 $mycreds = New-Object System.Management.Automation.PSCredential ($user, $secpasswd)

 #Build up the URL
 $url = "https://dyndns.loopia.se/?hostname=$hostname&myip=$myIp"
 #Invoke the URL
 $resp = Invoke-WebRequest -Uri $url -Credential $mycreds
 $resp.Content #Expected answers that I found "good","nochg","nohost","badauth","notfqdn"
}
Else
{
 #fake response if we didn't get any IP
 "NoDynIP"
}

Adapting the script for your account

Replace yourdomain.com with the domain name you want to set an IP address for, username with your Loopia Customer Zone username, and password with your Customer Zone password.

Credit to Pär at Powershell.today for the script!

Was this article helpful?

Related Articles