How Do
DIY DNS
DIY DNS

How to call the PHP code.

You can call the PHP code by entering the filename and parameters directly into a browser on your local network.

This is probably not the best way to do it because if you can do this then you probably are able to access your local network anyway.

But, this is a good simple test to make sure your code is working.

So, for example, if your website us iotha.co.uk, your PHP file is dns.php and your password is "password", just enter the following:


Call in a browser
http://iotha.co.uk/dns.php?pass=password

The browser will display the external IP address and will also be written to the file local_ip_address.txt on the server.


Now some more useful examples:

Raspberry Pi/Linux using crontab

On a Raspberry Pi you can call the code at regular intervals to ensure the IP address is always up to date.

First create a file diydyn in the /sbin directory as root 'sudo vi diydyn'.

Enter the following text in the file:

wget -spider http://iotha.co.uk/dns.php?pass=password

Change permissions to only allow root to read and modify and everyone else to execute: sudo chmod 711

Ensure it runs by typing diydyn and check it worked on the server.

To make it run with crontab:

Type:

crontab -e

This creates a new crontab if necessary.

Add the following line at the bottom of the crontab file and save (and add a new line after if it is at the end):

16 * * * * /sbin/diydyn >> /var/log/diydyn.log 2>&1

This causes script to be run at 16 minutes past every hour.

NOTE: '>' replaces the file. '>>' Creates or appends if it already exists.

Create the file /var/log/diydyn.log as root and change permissions :

sudo chmod 666 diydyn.log


PC Using C#

In C# you can use a static class to call the PHP code:


Call with C#
public static void UpdateDIYDyn(string Address)
{
    WebRequest request = WebRequest.Create(Address);
    WebResponse response = request.GetResponse();

    Console.WriteLine(((HttpWebResponse)response).StatusDescription);

    using (Stream dataStream = response.GetResponseStream())
    {
        StreamReader reader = new StreamReader(dataStream);
        string responseFromServer = reader.ReadToEnd();
        Console.WriteLine(responseFromServer);
    }
    response.Close();
}

And then call it with the following code:


Function Call
UpdateDIYDyn("http://iotha.co.uk/dns.php?pass=password");