DNS-O-MATIC Sync Service - .NET Windows Service

10:10 PM j. montgomery 3 Comments

I have been a fan of OpenDNS for a while - it is an excellent free service that will bring an additional layer of security to home and small/medium business networks at the DNS level by providing content filtering, phishing protection, domain blocking, adult site blocking, web proxy blocking, domain white-listing, and typo correction. They also claim to reduce the possibility of cache poisoning and pharming "due to its unique handling of DNS requests and multiple levels of validation applied to all DNS queries."1
Additional features (non-security related) include domain shortcuts and a very LARGE cache for speedy name resolution
The only trick (if you want to call it that) to receiving the all the features of OpenDNS is that they need to know your current public IP so it can be associated with your specific OpenDNS settings - this is simple if you have static public IP, but if you are assigned a dynamic IP you have to have a mechanism to notify OpenDNS of your current latest and greatest public IP. This is important whether at home or if you're out and about with your laptop on other public networks where the DNS servers may have been poisoned/hijacked/pharmed.
Because of the need to keep track of your changing public IP, OpenDNS created a service called DNS-O-Matic. DNS-O-Matic's purpose is to allow routers and software clients to notify them of your current public IP and they, in turn, will notify OpenDNS so your settings can follow you. However, DNS-O-Matic didn't just stop there, they also support notifying a myriad of other services that your IP has changed as well - services such as DynDNS, NO-IP.com, and of course OpenDNS. I think last I counted around 29 different services they will update for you.
I briefly looked at the API documentation for DNS-O-Matic and it really couldn't be any easier - it's a basic HTTP GET request with some URL parameters. With this information in hand, I decided to take a few hours on a weekend and bang out a Windows Service in .NET. It doesn't support all of the features of DNS-O-Matic (i.e. Dns-O-Matic will update MX records and other types of things the other services support), but this service supports the core one - updating your changing IP.
I took a few snippets of code I have found on various sites on the Internet and others techniques I have come up with and brought them together in this service. If you've never written a windows service, this would be a great project to take a look at as a primer. Things such as:
  1. Setting up a Windows Service Recovery Options programmatically and other Windows Service tricks in .NET - props to Neil Baliga's project titled "A ServiceInstaller Extension That Enables Recovery and Autostart Configuration" on codeproject.com.
  2. Changing a Windows Service DACL's to limit users' ability on the local system to stop/restart a service (via p/invoke - thanks to pinvoke.net)
  3. Using the System.Threading.Timer in coordination with the System.Diagnostics.StopWatch classes.
  4. Using the System.Threading.AutoReset class.
At least one of these I plan on blogging about in more detail at a later date.
Anyway - enough of the chatty-ness...I've listed the project as OpenSource on CodePlex under the New FreeBSD License:
DNS-O-Matic Sync Service for Windows


  1. Very nice trick. Thanks for the heads-up about OpenDNS--I've been rather indebted to you for this recommendation and have recently been flummoxed by it's failing to work. I think this explains it. You going to make a Mac version of your service?

    : )

  2. Glad to be of service! Try this - it runs on the Mac:
    1. DNS-O-Matic Updater 1.2 - if you need multiple service support (like dyndns)...
    2. If you just need to update OpenDNS only then try OpenDNS Updater 2.2.

    link here: http://web.mac.com/zweigand/zweisoft/

  3. Thanks for this. I've been stuck on Windows for a while since I got my new laptop, because I am too busy to backup, resize and install GNU/Linux, and had been messing around with rather hackish approaches for this in the meantime, like trying to use inadyn with srvany, and always had problems (I'm guessing some 64bit/32bit clashes). It was bothering me because the actual update API is so easy (like you say), I even have a Cygwin/Bash 3-liner script for doing it manually, but I've never even begun to look at the innards of Windows Services, so would always get stuck there... Thanks again!