aka Dynaminc DNS with 1and1.com
aka How to automate a Web Session with Delphi
Here’s a program I’ve been beta testing for a few months. I use it on a subdomain of TheCodeCave.com to allow me to always reach my home. I use Road Runner Cable from Time Warner and have a dynamic IP address. That means that my IP can change at any point in time. And it does!
I used to use the site Dyn.EE to provide a link to my house. I always liked them because their client is written in Delphi. However, now that I have TheCodeCave.com and a gazillion subdomains hanging off of it (MyIP.TheCodeCave.com, Webmail.TheCodeCave.com, Rot13.TheCodeCave.com and the list goes on) I thought I would also make an url that connected to my house.
This was tedious but quite duable to do once. You just go into the 1and1.com control panel, create the domain, wait for it to become functional, and then modify the DNS settings and override the A record. Simple right? Well mostly, it is just point and click at what seems logical.
However, that’s a pain to do on a regular basis because well…
- The UI is slow. The control panel takes for ever to get through.
- You have to first look up your own IP address first. I usually would call my wife and have her send me an email and I’d grab it from the email header and then fix the DNS. What a pain.
- Why suffer through minutes of clicking a few times a year when several hours of programming can get your around it?
So, I give you : The Code Cave’s Dynamic DNS Updater.
The usage is simple.
- Create a subdomain on your site and twiddle your thumbs til it becomes active sometime in the next hour or two.
- Enter that domain in the first field. NOTE: If you put your main URL, your main URL will no longer point at your website. Be careful! You want this to be something like: subdomain.example.com
- Enter the main password for your account. This is sent over HTTPS to 1and1.com and not to me. Have no fear. 😉 But it will appear in the debugging section if you check that “Show IE Data Sent” box.
- Click the Update 1and1.com Domain button and watch it work.
Your change should be available almost immediately, however, when debugging this program I sent the change a few (dozen) times and it eventually refused to allow any more updates to go through for another 24 hours. It’s been fine ever since. I’ve since changed the program so that does not try to update the DNS if the URL is already correctly set.
I’ve additionally made the program so that it takes the three fields mentioned above as parameters. You can put this into Windows XP’s scheduler and every 15 minutes, it will check the current IP and update as needed. Or just put it in your startup folder. This of course means your password will be put into your scheduler, but you have the source code, you can add encryption if that is a concern on your PC.
So, an easy way to do it would be to create a short cut in the startup folder to the program with the parameters like this:
tcc_DDNSUpdater URL PASSWORD DOMAINID
That will look something like this:
tcc_DDNSUpdater dyn.sample.com My1PaSsWoRd 12323213
The quickest way to get your domain ID is to run the program manually once and just click the Update 1and1.com Domain button. Then you can see the domain ID below.
The program follows this procedure recreating the required browsing session (so it is only as fast as your connection to 1and1.com).
- Go to MyIP.TheCodeCave.com and get the current IP address (This is a constant in the code and you can change it easily).
- Use a socket to retrieve the IP address for the URL you are looking up.
- If the two match, terminate the application.
- Navigate to Admin.1and1.com and get a session ID needed to establish the secure login.
- Login using HTTPS, the domain to update as the user name, and the provided password.
- If a Domain ID has not been provided, navigate to the list of domains and retrieve the ID of the domain (The subdomain HAS to be amoung the first 50 domains, alphabetically, on your account.)
- Navigate to the DNS update page for that domain (a requirement of the 1and1 Control Panel software)
- Submit the DNS record change.
Simple as that!
The full delphi source is available in the Zip file. The usual “If this crashes your site and costs you $30,000 dollars, why the heck did you run non-standard like this and risk a business site on it! I’m not responsible for your site’s safety you are. So consider the very real risk that things can go wrong with demo stuff downloaded off the Internet and err on the side of safety.” warning message applies.
I’ll post details of the code later.
I created this app using a Websession logger that might be of use to you. I use it in my automation processes at work and also us it to create forum submission links that I could not have book marked on the web in any other fashion.