Software, your way.
burger menu icon
WillMaster

WillMaster > LibraryWebsite Automation

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Automating DNS Change Propagation Check

When you change hosting providers or have other reason to change your domain's DNS, you'll want to test the website as soon as possible after the DNS has changed.

Does everything work? Perhaps not every page needs to be tested. But certainly every type of functionality — forms, links, database reading and writing.

The DNS can change nearly immediately or take up to 48 hours. The change has to propagate to every ISP in the world before everybody in the world can find the website at its new location.

How soon you can access the website's new location depends on your ISP. Many ISPs update their routers every hour or every several hours. Others might do it once a day.

Sitting around waiting for the DNS to propagate isn't the most efficient use of time. Nor is it efficient to intermittently interrupt other projects to do a manual check.

Here's one way to automate it:

  1. Make a web page to be used only for this automation. Let it have "Hello!" as it's content. It also has a JavaScript-generated meta tag to reload the page every 5 minutes.

  2. Make a copy of that page and upload it to the server at the previous DNS. Note its URL.

  3. To the original copy of the web page, add a bit of JavaScript to spawn a "DNS Changed!" alert box. Upload it to the server at the new DNS so it has the very same URL as the copy residing at the previous DNS.

  4. Load the web page URL into your browser. Let it run in a tab by itself while you use other tabs for other projects.

    When the DNS has changed, the tab will spawn the alert box.

It works because the first time the page reloads after your ISP has updated the DNS for the web site, it will get the page from the new location. And that new-location page has the JavaScript with the alert box.

Here is the source code for both versions of the web page.

The Web Page to Automate DNS Propagation Check

Here's the web page to upload to the server with the previous DNS.

<!DOCTYPE html>
<html>
<head>
<script>
document.write('<meta http-equiv="refresh" content="300; url=http://example.com/test.html?" + (new Date().getTime()) + ">');
</script>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Automated DNS Check</title>
</head>
<body>
<div style="text-align:center; font-size:1in;">
Hello!
</div>
</body>
</html>

On the fifth line of the above source code are two places to customize. One place is colored red and the other is colored blue.

  1. If desired, change 300 to the number of seconds to pause before the next page reload. The number 300 represents 300 seconds, which is 5 minutes. The 300 can be changed to any other number.

  2. Change the http://example.com/test.html URL to the URL of the web page when it's uploaded to the server with the previous DNS.

The reason the meta-refresh tag is generated with JavaScript is to append a different number to the URL every time the page is reloaded. It makes the browser recognize it as a different URL. The JavaScript timestamp is used for this.

When the browser sees the different URL (with the current timestamp appended after the "?" character), it won't find the URL in its cache. Therefore, it must load the page from scratch. This virtually guarantees the new DNS will be used the first time it's available on a page reload.

Paste this line of JavaScript into the web page for uploading to the new DNS server:

<script>alert("DNS Changed!")</script>

Paste the line of JavaScript anywhere into the web page. The example code below assumes a location immediately above the cancel </body> tag.

Here's the complete web page source code with the line of JavaScript inserted.

<!DOCTYPE html>
<html>
<head>
<script>
document.write('<meta http-equiv="refresh" content="300; url=http://example.com/test.html?" + (new Date().getTime()) + ">');
</script>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Automated DNS Check</title>
</head>
<body>
<div style="text-align:center; font-size:1in;">
Hello!
</div>
<script>alert("DNS Changed!")</script>
</body>
</html>

The line of JavaScript inserted into the above code is colored green.

Setting It Up

Upload the two web pages to their respective servers. Ensure they both have the same URL when the DNS is pointing to the server they're on.

Load the URL into your browser.

When you see the "DNS Changed!" alert message, the DNS has changed at your ISP.

(This article first appeared in Possibilities ezine.)

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC