Dynamic DNS instructions and an update “client” VBScript for freedns.afraid.org

Please note that this article is written in a light hearted way in order to appeal to IT novices and/or first time server runners!

Background

Whenever you run a server for your favourite PC games like Minecraft or voip like Ventrilo or TeamSpeak you sooner or later realize that sharing your IP-address just isn’t reliable enough. This is because your internet service provider (ISP) eventually changes your supplied address every now and then. This is due to the system of distributing a limited amount of IP-addresses and reallocate those that are not in use.

You can read more about the protocol that distributes IP’s (DHCP) here and the limitations of the most used IP-address system IPV4 here.

As you may know most websites have a registered domain name representing their company name or subject of interest. These domains are rented in a “first in, first served” manner to anyone by a company called ICANN which was founded in the beginning of the internet. While ICANN itself maintains the root zone it does not directly manage all the connections whenever someone presses enter after typing in an address, these are responded by intermediate service providers via a protocol named the domain name system protocol (DNS).

Now lets get back to the main point of this post; the solution for you trying to run your server!

Registering a subdomain

Instead of renting a complete domain by yourself you may instead look at alternative subdomain services that are free to use. One of these is the popular freedns.afraid.org

This free service has a very large selection of subdomains to choose from. For example your could register the following, (sorry if they’re already taken :D)

  • myminecraftserver.anydns.com
  • yourclan.epicgamer.org
  • yourname.mooo.org

freedns.afraid.org
The destination IP-address intentionally points too Google, I won’t be sharing mine!

Keeping your DNS updated

But here’s the thing, in order to keep myawesomeminecraftserver.anydns.com pointing to your IP-address you need to keep it updated and pointing to your current IP-address. In order to do this you need to configure some kind of script or client to check if your IP address has changed at regular intervals.

Instead of using a client or third party program for updating your Dynamic DNS you may prefer to be in total control of the code and actions and use a script similar to the following.

Fortunately freedns.afraid.org supplies an easy way to do this however you wish by supplying a link that you only need to click once in order to redirect the subdomain to your current IP-address. It works like a treat!

To find the link for your domain go here and click the Direct URL link to update your DNS to the current computer.

freedns.afraid.org2

In order to automate this URL in the script below, make sure to copy the full link.
The full link should look something like the following:

http://freedns.afraid.org/dynamic/update.php?herebemanyrandomletters

Please note that I have intentionally removed the random letters.

Scheduling the script

The easiest and most configurable way to make sure that this script runs regularly and in the right intervals according to your needs is to use windows task scheduler.

If you keep the computer that’s acting server constantly online I suggest that you add the condition to Run every day at a certain time.

Please don’t run it too often. Running every hour is too much I think. In regard to the subdomain provider, remember that we want to keep their traffic minimized as much as possible. We want to make sure they can keep delivering their services for free!

If you only keep the computer that’s acting server online when you’re using it (i.e. a travel laptop) I suggest that you also add the condition to Run at system startup and Run when a user logs in

The script

Copy and paste the following code into your favourite text editor or notepad (not MS Word!) and save as DNSUpdateURL.vbs or whichever name you prefer. Or download the script directly. Depending on your browser settings you may have to right click and select “save link as”.

You have to replace the updateURL = “” in settings to your Direct URL link (see above).

Keep the link inside the quotation marks and make sure that there are no accidental spaces at the beginning or the end.

' DNS URL Updater
' By Nirklars

'===================================================================================
'SETTINGS
'===================================================================================

'Change this file name to whichever you prever
logFileName = "DNSUpdateLog.txt"
'Change the path to whereever you prefer
logFileDirectory = "D:"
'This is where you copy and paste your own update url
updateURL = "http://freedns.afraid.org/dynamic/update.php?herebemanyrandomletters"

'===================================================================================
'DECLARATIONS
'===================================================================================

dim localPath, logFilePath

'Find local path where the script run from
localPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")

'Declare Log function variables
Dim logFile, oFSO
logFilePath = logFileDirectory & "\" & logFileName

'Declare File System object in order to write to log file
Set oFSO = CreateObject("Scripting.FileSystemObject")

'Declare http object
Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP.3.0")

'===================================================================================
'PROGRAM
'===================================================================================

Log(httpGET(updateURL))

'===================================================================================
'FUNCTIONS
'===================================================================================

'Retrieve a webpage
function httpGET(strURL)
	On Error Resume Next
		oXMLHTTP.Open "GET", strURL, False
		oXMLHTTP.Send
		If oXMLHTTP.Status = 200 Then
			httpGET = oXMLHTTP.responseText ' function return
		else
			httpGET = "http GET failed" ' function return
		end if
		oXMLHTTP.Close
end function

'Write to a logfile
sub Log (msg)
	if oFSO.FileExists(logFilePath) then
		Set oTextFileCheck = oFSO.GetFile(logFilePath)
		'Check if the log file has become larger than 1 mb
		if oTextFileCheck.Size > 1048576 Then
      'If its too large, delete it
			oTextFileCheck.Delete
		end if
	end if

	Set oTextFile = oFSO.OpenTextFile(logFilePath, 8, True)
	oTextFile.writeline date & " " & time & ": " & msg
	oTextFile.close
end sub

(GitHub)

Advertisements

5 Comments on “Dynamic DNS instructions and an update “client” VBScript for freedns.afraid.org”

  1. Quentin says:

    Hi there,

    I believe I have this correctly configured, but I receive the following in the log file:

    04/10/2014 3:33:23 AM: http GET failed
    04/11/2014 3:33:34 AM: http GET failed
    04/12/2014 3:33:23 AM: http GET failed
    04/13/2014 3:33:26 AM: http GET failed
    04/14/2014 3:33:35 AM: http GET failed

    Any suggestions as to where I may need to investigate this issue?
    Thanks

  2. dodd says:

    thanks so much
    works very easy
    from taiwan

  3. Wahana says:

    Hi.. this nice script..
    you have others methods for DynDns ?
    Thanks

    • nirklars says:

      Hello Wahana!

      DynDNS appears to also have links for browsers. You should be able to follow the same instructions but insert another link into the script.

      Here is how you get your link according to Dyn’s support:
      https://help.dyn.com/remote-access-api/perform-update/

      Something like this example should work:
      http://username:password@members.dyndns.org/nic/update?hostname=yourhostname&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG

      Replace username with your username and password with your password and yourhostname with your host name šŸ™‚

      I don’t recommend DynDNS because I used to have bad experience with them before due to some of the following reasons:
      – their basic usage used to be free of charge
      – they delete your account if you stop subscribing to them
      – they (used to) remove your subscription if you update your DNS without your IP having changed
      It was several years ago since I last used them and they might have improved since then.

      Best Regards


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s