dyndns script

spacecabbie

Verified User
Joined
Oct 11, 2019
Messages
127
Location
The Netherlands
Something useful i found online
Its indutch but essentially a script using the DA httpsocket php ( https://files.directadmin.com/services/all/httpsocket/ )

All credits go to the original poster: Jeroen S

PHP:
<?php

include 'httpsocket.php';

$server_login="username";
$server_pass="password";
$server_host="directadminserver"; //where the API connects to
$server_ssl="Y";
$server_port=2222;
$domains = ["domein1.nl", "domein2.nl", "domein3.nl", "domein4.nl", "domein5.nl", "domein6.nl"];

$url='http://ipecho.net/plain';
$ch=curl_init();
$timeout=5;

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);

$publicip=curl_exec($ch);

echo ("Public IPV4=".$publicip."\n");

curl_close($ch);

$data = json_decode(file_get_contents("directadminddns.dat"), true);
 
if ($data["publicip"] != $publicip)
{
    echo ("Public IP has changed to $publicip, updating dns...\n");

    foreach ($domains as $domain)
    {
 
    $sock = new HTTPSocket;
    if ($server_ssl == 'Y')
    {
        $sock->connect("ssl://".$server_host, $server_port);
    }
    else
    {
        $sock->connect($server_host, $server_port);
    }
 
    $sock->set_login($server_login,$server_pass);
 
    $sock->query('/CMD_API_DNS_CONTROL',
        array(
            'domain' => $domain,
        ));

    $result = $sock->fetch_parsed_body();
    var_dump ($result);

    $sock->query('/CMD_API_DNS_CONTROL',
        array(
            'domain' => $domain,
            'action' => 'select',
            'arecs0' => 'name='.$domain.'.',
        ));

    $result = $sock->fetch_parsed_body();
    var_dump ($result);

    $sock->query('/CMD_API_DNS_CONTROL',
        array(
            'domain' => $domain,
            'action' => 'add',
            'type' => 'A',
            'name' => $domain.'.',
            'value'    => $publicip,
        ));


    $result = $sock->fetch_parsed_body();

    }

        $data = array();
    $data["publicip"] = $publicip;
    file_put_contents("directadminddns.dat", json_encode($data));
}
else
{
    echo ("Public IP not changed, no update needed\n");
}
?>
 

Richard G

Verified User
Joined
Jul 6, 2008
Messages
5,690
Location
Maastricht
But that would be only with domains with Vimexx?

There are more threads about this on the DA forums like this one:

As you can read there in post #12 and #14 I also found some from a Dutch guy. And Sellerone changed it to a working one.
So I'm curious if this is indeed from Jeroen S. or if created it from the thread I mentioned.
And wondering which one works best/easiest.
 

spacecabbie

Verified User
Joined
Oct 11, 2019
Messages
127
Location
The Netherlands
But that would be only with domains with Vimexx?

There are more threads about this on the DA forums like this one:

As you can read there in post #12 and #14 I also found some from a Dutch guy. And Sellerone changed it to a working one.
So I'm curious if this is indeed from Jeroen S. or if created it from the thread I mentioned.
And wondering which one works best/easiest.

OH good point din't see that post even though i have searched for dyndns.
I have no clue who the origin is I just mentioned the source i got it from.

Although from first glance the original from DA Forum seems more adjusted for dyndns where as the one I linked runs standalone but require a web server running locally. I am working to change it to command line so i can run it in a cron job on my freenas.
The dyndns one is not relevant for me since that can easily be done with a cname.
 

Richard G

Verified User
Joined
Jul 6, 2008
Messages
5,690
Location
Maastricht
The dyndns one is not relevant for me since that can easily be done with a cname.
How do you mean? I'm also Dutch and don't understand everything.

I would also like to use a domain of my own and then a subdomain like sub.richard.nl as dyndns. But it has to be changed easily. Like with a protected web interface like no-ip.org and dyndns.org have. What exactly is done via a cname as you mention?
 

spacecabbie

Verified User
Joined
Oct 11, 2019
Messages
127
Location
The Netherlands
How do you mean? I'm also Dutch and don't understand everything.

I would also like to use a domain of my own and then a subdomain like sub.richard.nl as dyndns. But it has to be changed easily. Like with a protected web interface like no-ip.org and dyndns.org have. What exactly is done via a cname as you mention?
Basicaly you create a dyndns and then link a cname subdomain to it.

See https://daniel.haxx.se/blog/2012/08/20/fixed-name-to-dynamic-ip-with-cname/
 
Top