[英]How to check domain nameservers in PHP?
I need check what nameservers domain is using, but can't find correct solution in PHP. 我需要检查正在使用的名称服务器域,但是无法在PHP中找到正确的解决方案。
I have tried checkdnsrr();
我已经尝试过
checkdnsrr();
and dns_get_record();
和
dns_get_record();
, both of them do not show NS for some of domains that are working. ,但对于某些正常工作的域,它们都不显示NS。
Whois
is also not a solution. Whois
也不是解决方案。
My purpose is to filter domains which have nameserver set and which haven't. 我的目的是过滤设置了名称服务器而没有设置域名服务器的域。 Is there any solution for this?
有什么解决办法吗?
You should simple use dns_get_record
function and optionally you can pass DNS_NS
as second parameter. 您应该简单地使用
dns_get_record
函数,并且可以选择将DNS_NS
用作第二个参数。
For your domain zinas.lv
using 您的域
zinas.lv
使用
var_dump(dns_get_record('zinas.lv', DNS_NS));
I get: 我得到:
array(2) { [0]=> array(5) { ["host"]=> string(8) "zinas.lv" ["class"]=> string(2) "IN" ["ttl"]=> int(1655) ["type"]=> string(2) "NS" ["target"]=> string(10) "ns1.dns.lv" } [1]=> array(5) { ["host"]=> string(8) "zinas.lv" ["class"]=> string(2) "IN" ["ttl"]=> int(1655) ["type"]=> string(2) "NS" ["target"]=> string(10) "ns2.dns.lv" } }
array(2){[0] => array(5){[“主机”] =>字符串(8)“ zinas.lv” [“ class”] =>字符串(2)“ IN” [“ ttl”] => int(1655)[“ type”] =>字符串(2)“ NS” [“ target”] =>字符串(10)“ ns1.dns.lv”} [1] => array(5){[ “ host”] => string(8)“ zinas.lv” [“ class”] => string(2)“ IN” [“ ttl”] => int(1655)[“ type”] => string(2 )“ NS” [“ target”] =>字符串(10)“ ns2.dns.lv”}}
So you can simply display those 2 dns using: 因此,您只需使用以下命令即可显示这两个DNS:
$dns = dns_get_record('zinas.lv', DNS_NS);
echo $dns[0]['target'].' '.$dns[1]['target'];
Use this function to get the nameserver's of any domain as an array: 使用此函数可将任何域的名称服务器作为数组获取:
function getDns($domain)
{
$dns = dns_get_record($domain, DNS_NS);
$nameservers = [];
foreach ($dns as $current)
$nameservers[] = $current['target'];
return $nameservers;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.