C:\cd windows
C:\windows>win.exe

FreeDNS Management Tool

Posted on January 21st, 2016

Keep your FreeDNS address automatically updated with your ever changing dynamic IP Address.

Quick Download and Screenshot

FreeDNS Management Tool

What is the FreeDNS Management Tool?

First of all FreeDNS is a service, very similar to DynDNS, only with one very important difference. It’s free!

With FreeDNS you can bind your dynamic IP Address assigned by your ISP to a static domain, for example:

myname.domain.com

So every time your ISP changes your IP Address (might not be every day, week or even month, but unless you’re paying for a static IP Address, it will change) the new one is bound to the domain. This means you can always connect to your home network (to access files, connect to a VPN or even run a website) via the static domain.

The problem is how do you make sure each time your IP Address changes that your FreeDNS record knows about it? Plenty of routers and network attached devices support methods for doing this with paid services such as DynDNS. But we want to use the superior, and free, FreeDNS. That’s where this tool comes in; run it on the device you want to access externally (or any device on the network) and it allows you to mange all your FreeDNS domains from within your network. It supports the followings:

In short this is a tool that will make sure your FreeDNS domain(s) always have the correct IP Address.

Requirements

sudo apt-get install chromium-browser

Installation

The FreeDNS Management Tool is a simple PHP file. Simply edit the following line:

$freeDNSASCIIURL="[Enter Your ASCII API URL here - change to http if https]";

You can see the ASCII link here, remember to change https to http:

FreeDNS ASCII API

That’s it! Easy! Simply place the saved file on your Web Server and access via the browser (for example http://localhost/FreeDNS_Manager.php).

If you get an Internal Server Error (500), try changing the file permissions. For example in Linux:

chmod 777 FreeDNS_Manager.php

Port Forwarding

Depending on what you want to do with your FreeDNS domain, you may have to setup port forwarding on your router. Say for example you have an PC in your network that you want to run a web site on. You’d run this tool on the web server, that will match your external IP Address to your FreeDNS domain. Lets also say that the PC has an internal IP Address of 192.168.1.100. You would forward ports 80 and 443 in your router to 192.168.1.100. if you wanted to run an FTP server it would be port 21. For a full list of ports see http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers.

How to use the FreeDNS Management Tool

Service Overview/Update Status

FreeDNS Manager Overview

Update Status

This shows the update status of all your records. It will tell you if any attempt was made to update each record with your IP Address and what the result was.

FreeDNS Manager Update Status

Update Record(s)

The is allows you to update your selected records when you hit “Update Selected”. For a one time update, keep the Auto Update menu as the default “Auto Update Disabled”.

FreeDNS Manager Update Records

Your FreeDNS Record(s)

Each of your FreeDNS Records will be shown here.

FreeDNS Manager Record

Creating a FreeDNS Account

Of course you’ll need an account before you can begin.

FreeDNS Subdomain

FreeDNS Manager Dynamic DNS

You can edit your domains and IP Address setting via FreeDNS under the Dynamic DNS menu. Of course this isn’t automatic (that’s where this tool comes in). But there is one setting you should take note off, as it could cause confusion later on if you have more than 1 domain (it did for me!).

The Currently Linked button will read either ON or OFF. If ON each time you update one record then all of your records will be updated with the same IP Address… whether you selected them or not.

 

 

 

 

The Code

Copying the code directly will probably result in and internal server error when run. Highly recommended that you download one of the following:

<html>
<head>
 
  <!-- FreeDNS IP Address Update Tool -->
  <!-- Version 1.2 -->
  <!-- http://www.neil-black.co.uk/ -->
 
  <title>FreeDNS IP Address Updater</title>
  <style type="text/css">
  <!--
  body {
    background-color: #33322e;
    font-family: "Helvetica Neue", "Lucida Grande", Helvetica, Arial, Verdana, sans-serif;
    font-size: 10px;
    color: #303030;
  }
 
  table {
    margin: auto;
    background: #ffffff;
    border: 2px solid #000000;
    width: 780px;
    font-size: 11px;
  }
 
  .dualcol {
    width: 50%;
    padding: 5px;
  }
 
  .header1, .header2, .header3 {
    font-family: 'Pontano Sans', sans-serif;
    text-align: center;
    color: #bb0000;
    display: block;
  }
 
  .header1 {
    font-size: 20px;
    padding-top: 8px;
  }
 
  .header2 {
    font-size: 16px;
    padding-bottom: 8px;
  }
 
  .header3 {
    font-size: 16px;
    text-align: left;
  }
 
  .header4 {
    font-size: 11px;
    color: #303030;
    font-weight: 800;
    text-align: right;
    display: block;
  }
 
  .bold {
    font-weight: 800;
  }
 
  .align-right{
    align: right;
  }
 
  .status {
    text-align: center;
    display: block;
    color: #bb0000;
    background: #ede8e2;
    border-top: 1px solid #000000;
    border-bottom: 1px solid #000000;
    padding-top: 5px;
    padding-bottom: 5px;
  }
  -->
  </style>
</head>
<body>
<?php
  //Only edit this variable. Enter your Free DNS ASCII API URL. You can find this by logging into Free DNS and:
  //Dynamic DNS > Programmer's XML API > Available API Interfaces : XML | ASCII
  //Select ASCII and copy URL. It will look like (if https change to http):
  //http://freedns.afraid.org/api/?action=getdyndns&amp;sha=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
  $freeDNSASCIIURL="[Enter Your ASCII API URL here - change to http if https]";
 
  //Setup the variables we need. 
  $externalIP = file_get_contents('http://neil-black.co.uk/ip/ip.php');
  $updateStatus = "No Updates";
  $autoDescription = "Disabled";
  $autoTimer = -1;
  $autoUpdateURLS = "";
  $autoUpdateStatus = 0;
  $freeDNSstatusString = file_get_contents($freeDNSASCIIURL);
  $freeDNSstatusString = str_replace("\n", "|", $freeDNSstatusString);
  $freeDNSstatus = explode("|", $freeDNSstatusString);
  $numberRecords = sizeof($freeDNSstatus)/3;
 
  //Check to see if the auto update description cookie is there
  if (isset($_COOKIE["autoUpdateDescription"])) {
    $autoDescription = $_COOKIE["autoUpdateDescription"];
  }
 
  //Check to see if the auto uodate timer is there
  if (isset($_COOKIE["autoUpdateTimer"])) {
    $autoTimer = $_COOKIE["autoUpdateTimer"];
  }
 
  //Check to see if we have any post data
  if (sizeof($_POST) > 0) {
 
    if (isset($_COOKIE["autoUpdateTimer"])) {
      setcookie("autoUpdateTimer", "", time()-3600);
    }
 
    if (isset($_COOKIE["autoUpdateDescription"])) {
      setcookie("autoUpdateDescription", "", time()-3600);
    }
 
    if (isset($_COOKIE["autoUpdateRecords"])) {
      setcookie("autoUpdateRecords", "", time()-3600);
    }
 
    //Setup our auto update timers and descritions.
    if (isset($_POST['auto_update'])) {
      if ($_POST['auto_update'] == "off") {
        $autoDescription = "Disabled";
        $autoTimer = -1;
      }elseif ($_POST['auto_update'] == "15m") {
        $autoDescription = "Every 15 Minutes";
        $autoTimer = 60*15;
      } elseif ($_POST['auto_update'] == "30m") {
        $autoDescription = "Every 30 Minutes";
        $autoTimer = 60*30;
      } elseif ($_POST['auto_update'] == "1h") {
        $autoDescription = "Every 1 Hour";
        $autoTimer = 60*60;
      } elseif ($_POST['auto_update'] == "6h") {
        $autoDescription = "Every 6 Hours";
        $autoTimer = 60*60*6;
      } elseif ($_POST['auto_update'] == "12h") {
        $autoDescription = "Every 12 Hours";
        $autoTimer = 60*60*12;
      } elseif ($_POST['auto_update'] == "1d") {
        $autoDescription = "Every 1 Day";
        $autoTimer = 60*60*24;
      } elseif ($_POST['auto_update'] == "1w") {
        $autoDescription = "Every 1 Week";
        $autoTimer = 60*60*24*7;
      }
        setcookie("autoUpdateDescription", $autoDescription);
        setcookie("autoUpdateTimer", $autoTimer);
    }
 
    // Do the updates from POST. Check to see if auto update was selected
    $updateStatus = "";
    for ($i = 1; $i <= $numberRecords; $i++) {
      $domainLoc=($i-1)*3;
      $ipLoc=(($i-1)*3)+1;
      $updateLoc=(($i-1)*3)+2;
      $updateStatus .= "<span class=\"bold\">Record $i</span> ($freeDNSstatus[$domainLoc]) <br />";
      if ($_POST['ip_selection_'.$i] == "current") {
        $updateStatus .= file_get_contents($freeDNSstatus[$updateLoc]);
      } elseif ($_POST['ip_selection_'.$i] == "manual") {
        $updateStatus .= file_get_contents($freeDNSstatus[$updateLoc]."&amp;address=".$_POST['manual_ip_'.$i]);
      } else {
        $updateStatus .= "Record not selected. No attempt made.";
      }
      $updateStatus .= "<br /><br />";
 
      if ($_POST['ip_selection_'.$i] == "current") {
        $autoUpdateURLS .= "Record ".$i."|".$freeDNSstatus[$domainLoc]."|".$freeDNSstatus[$ipLoc]."|".$freeDNSstatus[$updateLoc]."|"."1|";
        $autoUpdateStatus = 1;
      } else {
        $autoUpdateURLS .= "Record ".$i."|".$freeDNSstatus[$domainLoc]."|".$freeDNSstatus[$ipLoc]."|".$freeDNSstatus[$updateLoc]."|"."0|";
      }
    }
    $autoUpdateURLS=substr($autoUpdateURLS, 0, -1);
    setcookie("autoUpdateRecords", $autoUpdateURLS);
  }
 
  if ($autoTimer != -1 &amp;&amp; sizeof($_POST) == 0 ) {
    $autoUpdateRecords = explode("|", $_COOKIE["autoUpdateRecords"]);
    $numberAutoUpdateRecords = sizeof($autoUpdateRecords)/5;
 
 
    $updateStatus = "";
    for ($i = 0; $i < $numberAutoUpdateRecords; $i++) {
    //Update Records as per auto update selection.
      $recordLoc=$i*5;
      $domainLoc=($i*5)+1;
      $ipLoc=($i*5)+2;
      $liveIPLoc=($i*3)+1;
      $updateLoc=($i*5)+3;
      $updateAttempt=($i*5)+4;
      if ($autoUpdateRecords[$updateAttempt] == 1) {
        if ($freeDNSstatus[$liveIPLoc] !== $externalIP) {
          $updateStatus .= "<span class=\"bold\">".$autoUpdateRecords[$recordLoc]."</span> (".$autoUpdateRecords[$domainLoc].")\n<br />\n".file_get_contents($autoUpdateRecords[$updateLoc])."<br /><br />\n";
        } else {
          $updateStatus .= "<span class=\"bold\">".$autoUpdateRecords[$recordLoc]."</span> (".$autoUpdateRecords[$domainLoc].")\n<br />\n External IP Address and current record already match. No attempt made. <br /><br />\n";
        }
      } else {
        $updateStatus .= "<span class=\"bold\">".$autoUpdateRecords[$recordLoc]."</span> (".$autoUpdateRecords[$domainLoc].")\n<br />\n Record not selected. No attempt made. <br /><br />\n";
      }
    }
  } elseif ($autoTimer !== -1) {
    if ($autoUpdateStatus == 0) {
      $updateStatus = "Please select at least one Record as \"Update IP Address (external IP)\" when using Auto Update.";
    }
  }
 
  //Do the auto update page refresh
  if ($autoTimer !== -1) {
    $page = $_SERVER['REQUEST_URI'];
    $sec = $autoTimer;
    header("Refresh: $sec; url=$page");
  }
?>
 
  <form action="<?php echo getenv('SCRIPT_NAME'); ?>" name="freeDNSupdate" method="post">
  <table>
    <tr>
      <td colspan="2"><span class="header1">FreeDNS IP Address Update Tool</span></td>
    </tr>
    <tr>
      <td colspan="2"><br/></td>
    </tr>
    <tr>
      <td colspan="2"><span class="header2">Service Overview/Update Status</span></td>
    </tr>
    <tr>
      <td class="dualcol"><span class="header4">Current External IP:</span></td>
      <td class="dualcol"><?php echo $externalIP; ?></td>
    </tr>
    <tr>
      <td class="dualcol"><span class="header4">Free DNS Record(s):</span></td>
      <td class="dualcol"><?php echo $numberRecords; ?></td>
    </tr>
    <tr>
      <td class="dualcol"><span class="header4">Last Updated:</span></td>
      <td class="dualcol"><?php echo date('D, d M Y H:i:s T') ?></td>
    </tr>
    <tr>
      <td class="dualcol"><span class="header4">Auto Update Status:</span></td>
      <td class="dualcol"><?php echo $autoDescription ?></td>
    </tr>
    <tr>
      <td colspan="2"><br/></td>
    </tr>
    <tr>
      <td colspan="2"><span class="status"><?php echo $updateStatus ?></span></td>
    </tr>
    <tr>
      <td colspan="2"><br/></td>
    </tr>
    <tr>
      <td colspan="2"><span class="header2">Update Record(s)</span></td>
    </tr>
    <tr>
      <td class="dualcol" align="right">
        <select name="auto_update" class="align-right">
          <option value="off" selected>Auto Update Disabled</option>
          <option value="15m" >15 Minutes</option>
          <option value="30m" >30 Minutes</option>
          <option value="1h" >1 Hour</option>
          <option value="6h" >6 Hours</option>
          <option value="12h" >12 Hours</option>
          <option value="1d" >1 Day</option>
          <option value="1w" >1 Week</option>
        </select>
      </td>
      <td class="dualcol"><input type="submit" value="Update Selected" /></td>
    </tr>
    <tr>
      <td colspan="2"><br/></td>
    </tr>
    <tr>
      <td colspan="2"><span class="header2">Your FreeDNS Record(s)</span></td>
    </tr>
  </table>
  <br />
 
<?php
  $freeDNSstatusString = file_get_contents($freeDNSASCIIURL);
  $freeDNSstatusString = str_replace("\n", "|", $freeDNSstatusString);
  $freeDNSstatus = explode("|", $freeDNSstatusString);
  $numberRecords = sizeof($freeDNSstatus)/3;
  for ($i = 1; $i <= $numberRecords; $i++) {
    $domainLoc=($i-1)*3;
    $ipLoc=(($i-1)*3)+1;
    $updateLoc=(($i-1)*3)+2;
    echo "\t<table>\n";
    echo "\t\t<tr>\n";
    echo "\t\t\t<td><br /></td>\n";
    echo "\t\t\t<td colspan=\"2\"><span class=\"header3\">Record $i</span></td>\n";
    echo "\t\t</tr>\n";
    echo "\t\t<tr>\n";
    echo "\t\t\t<td><br /></td>\n";
    echo "\t\t\t<td><span class=\"bold\">Domain:</span></td>\n";
    echo "\t\t\t<td><a href=\"http://$freeDNSstatus[$domainLoc]\" target=\"_blank\">$freeDNSstatus[$domainLoc]</a></td>\n";
    echo "\t\t</tr>\n";
    echo "\t\t<tr>\n";
    echo "\t\t\t<td><br /></td>\n";
    echo "\t\t\t<td><span class=\"bold\">Record IP Adress:</span></td>\n";
    echo "\t\t\t<td>$freeDNSstatus[$ipLoc]</td>\n";
    echo "\t\t</tr>\n";
    echo "\t\t<tr>\n";
    echo "\t\t\t<td><input type=\"radio\" name=\"ip_selection_$i\" id=\"record_$i\" value=\"current\" /></td>\n";
    echo "\t\t\t<td><span class=\"bold\">Update IP Address (external IP):</span></td>\n";
    echo "\t\t\t<td><a href=\"$freeDNSstatus[$updateLoc]\" target=\"_blank\">$freeDNSstatus[$updateLoc]</a></td>\n";
    echo "\t\t</tr>\n";
    echo "\t\t<tr>\n";
    echo "\t\t\t<td><input type=\"radio\" name=\"ip_selection_$i\" id=\"record_$i\" value=\"manual\" /></td>\n";
    echo "\t\t\t<td><span class=\"bold\">Update IP Address (manual IP):</span></td>\n";
    echo "\t\t\t<td><input type=\"text\" name=\"manual_ip_$i\" value=\"$freeDNSstatus[$ipLoc]\" size=\"15\" maxlength=\"15\" /></td>\n";
    echo "\t\t</tr>\n";
    echo "\t\t<tr>\n";
    echo "\t\t\t<td><input type=\"radio\" name=\"ip_selection_$i\" id=\"record_$i\" value=\"none\" checked=\"checked\" /></td>\n";
    echo "\t\t\t<td><span class=\"bold\">Do not update</span></td>\n";
    echo "\t\t\t<td><br /></td>\n";
    echo "\t\t</tr>\n";
    echo "\t</table>\n";
    echo "<br />";
  }
?>
</form>
 
</body>
</html>