I've been trying to find out how to detect what parent nameserver is associated with a domain name. For example, when you search for a domain name using intoDNS, it displays results for both the 'normal' and parent nameservers. They mention what the parent nameserver is, like this:
k.gtld-servers.net was kind enough to give us that information.
But how did they know they had to query this specific nameserver? A few examples of what the parent nameserver is:
stackoverflow.com k.gtld-servers.net
google.com c.gtld-servers.net
ycombinator.com a.gtld-servers.net
asp.net g.gtld-servers.net
google.nl sns-pb.isc.org
google.de z.nic.de
It seems all generic TLDs can be queried at a certain subdomain of gtld-servers.net
.
Right now, I find the 'normal' nameservers in PHP like this:
$nameservers = dns_get_record($domain_name, DNS_NS);
So, I'd like to know, how can I find out what the parent nameserver is for a specific domain and how can I query this using PHP?
I've found out that UNIX' nslookup
tool accepts a server parameter. If it's left empty, it returns the same results as PHPs dns_get_record
, but if it one of the root servers for that top-level domain as specified on http://www.iana.org/domains/root/db, it will return the same results as intoDNS lists as the results of the parent server.
The only problem left is how to query this specific server, as I'd greatly prefer not to use exec()
to call nslookup
directly. Does anyone know of an alternative to dns_get_record
which does allow you to specify the server?
I've found out how to do it. I had to use NET_DNS2 PEAR package for this, because it allows you to specificy which DNS server to use. If I specify one of the servers listed in the file nickc mentioned:
http://www.iana.org/domains/root/db
(you have to use one of the servers for the top-level domain you're querying, it doesn't matter which one)
require 'Net/DNS2.php';
$server = gethostbyname('j.gtld-servers.net'); // 192.48.79.30
$r = new Net_DNS2_Resolver(array('nameservers' => array($server)));
$result = $r->query('stackoverflow.com', 'NS');
print_r ($result);
This will print:
...
[authority] => Array
(
[0] => Net_DNS2_RR_NS Object
(
[nsdname] => ns1.webfaction.com
[name] => webassay.com
[type] => NS
[class] => IN
[ttl] => 172800
[rdlength] => 17
[rdata] => ns1webfaction�
)
[1] => Net_DNS2_RR_NS Object
(
[nsdname] => ns2.webfaction.com
[name] => webassay.com
[type] => NS
[class] => IN
[ttl] => 172800
[rdlength] => 6
[rdata] => ns2�.
)
[2] => Net_DNS2_RR_NS Object
(
[nsdname] => ns3.webfaction.com
[name] => webassay.com
[type] => NS
[class] => IN
[ttl] => 172800
[rdlength] => 6
[rdata] => ns3�.
)
)
...
This matches the nameservers listed as returned by the parent server at intoDNS: http://www.intodns.com/stackoverflow.com
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With