DtDNS and automatic update

Introduction

On the previous page we looked at how to obtain your current IP address. Knowing this it is possible to determine if that IP has changed covered later.

If the IP address has changed we need a method to inform DtDNS to update the value it currently holds.

Example Code

This script is based on a template taken from the cURL tutorial found on this page.

Although an IP can be provided it is optional, DtDNS will determine you current IP from the page request hence removed this from the URL.

Substitute your real id (host name) and password.

  • Substitute uni.dtdns.net for your host name that you wish to update
  • Substitute me123 for your account password
<?php
$id_val     = urlencode('uni.dtdns.net'); // User Host on DtDNS
$pw_val     = urlencode('me123');         // User password

$client_val = urlencode('UniServerV1');         // Optional - But added it
$url = 'https://www.dtdns.com/api/autodns.cfm'; // DtDNS update page

// Build complete URL
$str= $url."?id=".$id_val."&pw=".$pw_val."&client=".$client_val;

// Access page using Curl SSL
$ch=curl_init();                                 // Initialize Curl and save memory location in variable $ch
curl_setopt($ch,CURLOPT_URL,$str);               // Set the Curl URL option to the URL we wish to work with
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // no verify
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,10);      // timeout set to 10 sceonds
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);       // force curl_exec to ouput string 
$buffer = curl_exec($ch);                        // run above, save returned page to buffer
curl_close($ch);                                 // Close Curl frees memory

// Test returned page 
if(preg_match("/now\spoints\sto/",$buffer)){     // Test for "now points to"
 print " Update successful";                     // Crude but works
}
else{                                            // Failed
 print "Update failed";
}
?>

Top

Test 3 - Server

The script will run on a server, perform the following test:

  • Create a new text file in folder C:\dtdns_test\UniServer\www and name it dtdns_test_3.php add the above code.
  • Remember to substitute your ID and password.
  • Run servers
  • Type http://localhost/dtdns_test_3.php into your browser
  • Result: Update successful displayed

Top

Test 4 - PHP CLI

We require the script to run in PHP CLI mode.

  • Copy file C:\dtdns_test\UniServer\www\dtdns_test_3.php to folder C:\dtdns_test\UniServer\plugins\dtdns_updater.
  • Inside folder dtdns_updater create a new text file Run_dtdns_test_3.bat with the folowing content:

Run_dtdns_test_3.bat

COLOR B0
@echo off
cls

rem ### working directory current folder 
pushd %~dp0

..\..\usr\local\php\php.exe  dtdns_test_3.php

rem ### restore original working directory
pause
popd
EXIT

Run Test 4:

  • Close servers
  • Double click on Run_dtdns_test_3.bat
  • Result: Update successfulPress any key to continue . . .

Top

Summary

I have shown how easy Curl is to use and how to access DtDNS secure IP update page. The code can be used in either server or CLI mode. The code example again is only part of a solution we require a method of tracking what IP address DtDNS is using. Knowing this a comparison can be made with the real current IP address and an update made if required.

The next page covers two tracking methods.

Top