DNS Lookup in PHP

流过昼夜 提交于 2019-12-31 00:44:26

问题


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.


回答1:


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




回答2:


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




回答3:


but there is a little limitation of that function is Changelog: v. PHP 5.3.0 - This function is now available on Windows platforms.

if you dont want to update php on IIS. there is another alternative that executing dig for windows binary. here is dig for windows. you may also need that for your own not for any program. it's beyond of old-not-enough nslookup command.




回答4:


"Ping " always performs a DNS lookup (both forward and reverse) before pinging the hostname in question. Writing a shell script to use ping (or dig) to see if ping is acting wonky is left as an exercise to the reader.

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



来源:https://stackoverflow.com/questions/1113638/dns-lookup-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!