WinHttp.WinHttpRequest

Creation date: 5/15/2026 2:38 AM    Updated: 5/15/2026 2:41 AM    requette winhttp winhttprequest

Dim http, url, login, password, hostname

login    = "your-login"
password = "your-pass"
hostname = "your-dynamic-host.ddns.ma"

' Step 1: Get current public IP
Set http = CreateObject("WinHttp.WinHttpRequest.5.1")
http.Open "GET", "http://checkip.dyndns.org/", False
http.Send

' Parse IP from response: "Current IP Address: x.x.x.x"
Dim ip, matches
Set matches = New RegExp
matches.Pattern = "(\d+\.\d+\.\d+\.\d+)"
Set m = matches.Execute(http.ResponseText)
ip = m(0).Value

' Step 2: Update DDNS (dyndns2 protocol)
url = "https://www.ddns.ma/nic/update?hostname=" & hostname & "&myip=" & ip

Set http = CreateObject("WinHttp.WinHttpRequest.5.1")
http.Open "GET", url, False
http.SetCredentials login, password, 0  ' 0 = HTTPREQUEST_SETCREDENTIALS_FOR_SERVER
http.Send

WScript.Echo "Status: " & http.Status & " - " & http.ResponseText
' Expected responses:
'   "good 1.2.3.4"  = success, IP updated
'   "nochg 1.2.3.4" = no change needed
'   "badauth"        = wrong credentials
'   "nohost"         = hostname not found

Set http = Nothing

For ASP Classic / VBA, same logic — just replace WScript.Echo with Response.Write or Debug.Print.

Key points:

  • The dyndns2 update endpoint is always /nic/update with Basic Auth
  • SetCredentials ..., 0 sends HTTP Basic authentication
  • Don't call the update too frequently — ddns.ma may block abuse (every 300s minimum, as in your config)
  • If you omit &myip=, the server uses the caller's IP automatically (simpler if the request comes from the machine itself)