Jump to content

A Simple Script To Display The Nameserver?


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?




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:

if ($d) {
    $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:



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




Do you know why this is?




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.

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.

  • Create New...