Jump to content

A Simple Script To Display The Nameserver?


purplespider
 Share

Recommended Posts

I'm looking for a simple PHP/CGI script to display the nameserver of a set, hard coded, domain. The reason being I would like a page which simply lists all my domains and next to them displays their nameservers?

 

Is this possible?

 

Thanks,

James

Link to comment
Share on other sites

PHP5 will make this easier, but that's still beta so...

 

If you get the Pear Net_DNS library that Raul recommended above, put it into the directory you want to create a script to use it, then extract the contents using File Manager, and rename the directory it creates to "Net" (the latest package will create a directory called "Net_DNS-1.00b2", that's what you need to rename). You can delete the compressed file after that.

 

Then here's a script that would do what you want:

><?php
if ($d) {
    require_once("Net/DNS.php");
    $res = new Net_DNS_Resolver();
    $res->debug = 0;
    $result = $res->search($d, "NS");
    foreach ($result->answer as $rec)
        print($rec->nsdname."<br />");
} else
    echo "You didn't give me anything to lookup.";
?>

 

For an example of the output:

http://biggorilla.com/tools/ns.php?d=google.com

 

My recommendation would be to use the script just like above, and include it wherever you need the results. Just change the value of "d" accordingly. So, if you had the script in the directory "tools" under public_html, then whever you wanted the nameservers to output in a page:

 

><?php include("http://yoursite.com/tools/ns.php?d=domain.com"); ?>

 

Just do not link to my site for that include (I'll eventually remove my installed script). :D

 

I leave any further customization for your needs as an exercise for you. ;)

Link to comment
Share on other sites

Oh...btw, I should have mentioned this is done via DNS lookups, not WHOIS lookups. That means it will display information as it's retrieved from the DNS server that it queries.

 

Why that's important is because when a domain account is created on TCH servers, the nameservers will show as TCH's when this script is run on those servers even if your domain really has them somewhere else.

 

To get nameservers from Whois information is considerably more complex because different domain types return records in different formats.

Link to comment
Share on other sites

Thanks Mike! Thats perfect apart from when I do the included it says

 

" Warning: main(): stream does not support seeking in /home/purplesp/public_html/status/index.php on line 62

ns2.totalchoicehosting.com

ns1.totalchoicehosting.com"

 

Do you know why this is?

 

Cheers

James

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...