Friday, March 24, 2006


Calling nsupdate from PHP script

First, I should note that this is very situational but hopefully someone can make use of it. The environment at work is mostly Windows machines. There is a Windows DNS server as well which accepts dynamic updates for reverse lookups, among other things. This can be a pain when you are working on various Unix/Linux platforms. I wrote up a very quick web page that uses the nsupdate package (should be available for most platforms) to remove stale reverse lookup entries from the server. Released public domain, a comment here would be appreciated if it helped you at all.

<title>Jamie's DNS fixer thingy</title>
<P>This tool clears reverse lookup entries for a given IP.  Stale reverse lookup
entries can cause problems with non-Windows systems.  Entering an IP here submits
a dynamic update request to the DNS server for removal of the entry for that IP.</P>
<form method="POST">
    <input name="IP" type="text" value="<?=(!empty($_POST['IP'])) ? $_POST['IP'] : ""?>">
    <input name="Submit" type="submit"/>


$valid preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/'$input);
    if (isset(
$_POST['Submit'])) {
        if (!
$valid) {

<p><?=empty($input) ? "You must specify an IP address." "$input is not a valid IP address."?></p>

<?  } else { // Input validated by regexp
$iparr split('\.'$input);
$iprev $iparr[3].'.'.$iparr[2].'.'.$iparr[1].'.'.$iparr[0];
$dnscmd = <<<EOF
update delete {$iprev}

$nsupdate popen('/usr/bin/nsupdate''w');
$retval pclose($nsupdate); // nsupdate doesn't return anything useful when called this way

<p>Submitted removal request for stored DNS record on <?=$input?>.

// if(!$valid)
// if(isset($_POST['Submit']))

Just to say thanks for this.
I used it as a base to add and remove dns entries.
Great Post, Actually PHP is a beautiful source for developing a database driven web application, I love this post, thanks for spending your time for discussing about this topic.
PHP Course in Chennai
In recent days Angular plays vital role to loading your site content in a fastest way, so it’s a required skill for everyone, thanks for sharing this useful information to our vision keep blogging.
Angularjs training in chennai
Thanks for sharing this unique and informative content which provided me the required information.
PHP Training in Chennai | PHP Course in Chennai | FITA Velachery
Well Said, you have furnished the right information that will be useful to anyone at all time. Thanks for sharing your Ideas.
Hadoop Training Chennai | Hadoop course in Chennai
very nice and informative blog
dot net training in chennai
java training in chennai
This blog is very informative about the concepts involved in hadoop and its scope in future. Interesting concepts on its architectute and syllabus which are covered by big data hadoop training institute in Chennai that is functioning effectively.
Thanks for nice blog and article, very much informative.
Java Training in chennai|Dot Net Training in chennai
Post a Comment

Links to this post:

Create a Link

<< Home

This page is powered by Blogger. Isn't yours?