windows PHP 中的 DNS 查找
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1113638/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
DNS Lookup in PHP
提问by Dave Forgac
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.
我有一台 Windows 服务器,它间歇性地失去了查找 DNS 信息的能力。我试图找到问题的根本原因,但同时我希望能够监控服务器是否可以执行查找。
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.
该站点运行 PHP,因此我希望监视器脚本使用 PHP,但如果有人知道如何在 ASP/.Net 中执行此操作,那也可以。
回答by Rodney Amato
http://www.php.net/manual/en/function.dns-get-record.phpis the function in php it sounds like you are after.
http://www.php.net/manual/en/function.dns-get-record.php是 php 中的函数,听起来像是您在追求。
回答by bucabay
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
在 PHP 5.3 之前的 Windows 上,PHP DNS 函数本机不可用。您将需要 Pear Net_DNS 类。 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');
来源:http: //code.google.com/p/php-smtp-email-validation/source/browse/trunk/smtp_validateEmail.class.php#232
回答by samiam
"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.
“Ping”总是在 ping 有问题的主机名之前执行 DNS 查找(正向和反向)。编写一个 shell 脚本来使用 ping(或 dig)来查看 ping 是否表现不佳,留给读者作为练习。
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)
另一种选择是在本地机器上使用缓存 DNS 服务器,该服务器缓存来自上游 DNS 服务器的回复,并在上游关闭时从缓存发送数据。我自己的 Deadwood 是一个很小的 32k Windows 或 UNIX 二进制文件,可以做到这一点(如果你想要完整的 DNS 递归,则为 64k)
回答by risyasin
but there is a little limitation of that function is Changelog: v. PHP 5.3.0 - This function is now available on Windows platforms.
但该功能有一点限制是 Changelog: v. PHP 5.3.0 - 此功能现在可在 Windows 平台上使用。
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.
如果您不想在 IIS 上更新 php。还有另一种替代方法可以为 Windows 二进制文件执行 dig。这是dig for windows。您可能还需要自己的而不是任何程序。它超出了旧的不够用的 nslookup 命令。