Page 1 of 1

How to specify which DNS server for gethostbyname/checkdnsrr

Posted: Mon Nov 23, 2009 7:45 am
by Apollo
Functions like gethostbyname and checkdnsrr depend on a DNS server to resolve domain names or find DNS records.

Unfortunately, some providers by default use DNS servers that resolve *any* address, even non-existing ones. Non-existing domain names are typically resolved to some generic bogus advertisement page. Which is real bad practice imho, intended to fool users who make typos.

In my case for example, gethostbyname('non.existing.domain.blablabla') returns '92.242.140.13' which results in this bullcrap :(

Is there a way I can specify a different DNS server to be used, at script level?

Re: How to specify which DNS server for gethostbyname/checkdnsrr

Posted: Mon Nov 23, 2009 10:23 am
by iankent
I don't think PHP can do it directly becase it relies on the servers configuration (though I may be wrong!)

You could always use shell_exec() to run the nslookup command manually, which does let you specify which DNS servers to use for the lookup, e.g.

Code: Select all

 
$output = shell_exec('nslookup hostname.com 1.2.3.4');
 
where hostname.com = the name you're looking up and 1.2.3.4 = the DNS server you want to check against

hth

Re: How to specify which DNS server for gethostbyname/checkdnsrr

Posted: Tue Nov 24, 2009 2:41 pm
by Apollo
Thanks, as a quick 'n dirty fix I will now simply check if the result is '92.242.140.13' and in that case consider the domain invalid.

I hope the ICANN or whoever is in charge will soon BAN this kind of rotten DNS providers from the interwebs, and forbid fake name resolving merely for advertisement purposes (prolly not gonna happen :().