Intro

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 #récupération de l'adress IP stocké dans PS.ip
	If ([IPAddress]$currentIP -eq [IPAddress]$IP) #comparaison de l'ancienne et de la nouvelle adresse
	{
		Write-Host meme ip, ne rien faire
	}
	Else
	{
		Write-Host ip différente
		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 :

Licence Creative Commons
This websitehttp://shebangthedolphins.net is licensed to the public under a licence Creative Commons Attribution licence.
Contact :