DNS lookup in PHP

I have a Windows server that periodically loses the ability to look up DNS information. I am trying to find the root cause of the problem, but at the same time I would like to track if the server can do a search.

Basically, he should try to find some common hostnames and display "Success" if the search queries are successful.

The site runs PHP, so I would prefer the script monitor to be in PHP, but if someone knows how to do this in ASP / .NET, this will work too.

+4
source share
4 answers

http://www.php.net/manual/en/function.dns-get-record.php is a function in php that sounds like you are after.

+6
source

In Windows PHP, DNS functions are not available initially until PHP 5.3. You will need the Pear Net_DNS class. http://pear.php.net/package/Net_DNS

Usage example:

require_once 'Net/DNS.php'; $resolver = new Net_DNS_Resolver(); $resolver->debug = $this->debug; // nameservers to query $resolver->nameservers = array('192.168.0.1'); $resp = $resolver->query($domain, 'A'); 

source: http://code.google.com/p/php-smtp-email-validation/source/browse/trunk/smtp_validateEmail.class.php#232

+2
source

but there is a slight restriction on this feature. Changelog: v. PHP 5.3.0 - This feature is now available on Windows platforms.

if you do not want to upgrade php on IIS. there is another alternative that does dig for Windows binaries. dig here for windows . You may also not need this for you for any program. this outside the old nslookup command is not enough.

0
source

"Ping" always does a DNS lookup (both forward and backward) before starting a hostname check. By writing a shell script to use ping (or digging) to see if ping is working in standby mode, it remains as an exercise for the reader.

Another option is to use a caching DNS server on the local computer, which caches responses from the upstream DNS server and sends data from the cache when the upstream is down. My own Deadwood is a tiny 32-bit Windows or UNIX binary that can do this (64k if you want full DNS recursion)

0
source

All Articles