DNS-O-MATIC Sync Service - .NET Windows ServiceI 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:
- 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.
- 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)
- Using the System.Threading.Timer in coordination with the System.Diagnostics.StopWatch classes.
- Using the System.Threading.AutoReset class.
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