rss logo

PowerShell Script to dyndns update

2020.10 : it doesn't seem to work anymore.

A PowerShell script to update dyndns on OVH.

Code

###########################
# author : shebangthedolphins.net
# version : 1.0
# date : 2016.04
# role : Update Dyndns on OVH
# other : need curl.exe to work
# updates :
#       - 1.X (x/x/xxxx) :    

# initialisation des variables
$url = "http://monip.org/"
$webclient = new-object System.Net.WebClient
$currentIP = [IPAddress]$webclient.DownloadString($url)
$OVHUSER = "MYUSER"
$OVHPASS = "MYPASSWD"
$OVHDYNHOST = "HOST.ORG"

If ($currentIP -match "(?:[0-9]{1,3}.){3}[0-9]{1,3}") #check ip format
{
	Try { Get-ChildItem C:\scripts\dyndns\PS.ip -ErrorAction Stop > $null }
	Catch { Write-Output $currentIP > C:\scripts\dyndns\PS.ip }
	[IPAddress]$IP = Get-Content C:\scripts\dyndns\PS.ip # get ip address from PS.ip file
	If ([IPAddress]$currentIP -eq [IPAddress]$IP) # compair ip file with current ip
	{
		Write-Host "same ip, I don't do anything"
	}
	Else
	{
		Write-Host "ip are differents"
		Write-Output $currentIP.IPAddressToString > C:\scripts\dyndns\PS.ip #we put ip adress inside a table

		& "C:\scripts\dyndns\curl.exe" "-k" "--basic" "https://$($OVHUSER):$($OVHPASS)@www.ovh.com/nic/update?myip=$($currentIP)`&hostname=$($OVHDYNHOST)`&system=dyndns" #we execute curl.exe, "`" is an escapre character.
	}
}
Else
{
	Write-Host "No IP"
}

Scheduled Task

We can schedule the standby :

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Contact :

contact mail address