Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DNS Lookup in PHP

Tags:

php

windows

dns

I have a Windows server that is intermittently losing the ability to lookup DNS information. I'm trying to get to the root cause of the problem but in the mean time I'd like to be able to monitor whether the server can perform lookups.

Basically, it should attempt to lookup some common hostnames and the display 'Success' if the lookups are successful.

The site runs PHP so I'd prefer that the monitor script be in PHP but if someone knows how to do this in ASP / .Net that would work as well.

like image 751
Dave Forgac Avatar asked Jul 11 '09 12:07

Dave Forgac


2 Answers

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

like image 109
Rodney Amato Avatar answered Oct 04 '22 17:10

Rodney Amato


On windows PHP DNS functions are not available natively prior to PHP 5.3. You will need the Pear Net_DNS Class. http://pear.php.net/package/Net_DNS

Example usage:

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

like image 22
bucabay Avatar answered Oct 04 '22 16:10

bucabay