How to specify which DNS server for gethostbyname/checkdnsrr

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

How to specify which DNS server for gethostbyname/checkdnsrr

Post 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?
User avatar
iankent
Forum Contributor
Posts: 333
Joined: Mon Nov 16, 2009 4:23 pm
Location: Wales, United Kingdom

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

Post 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
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

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

Post 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 :().
Post Reply