使用dns_get_record()获取权威名称服务器会导致$ authns为null

时间:2013-09-17 13:26:57

标签: php dns

我想获得域的权威名称服务器。 dns_get_record()似乎很直接,应该能够将权威的名称服务器填充到$authns

如果我从手册中运行示例:

<?php
$result = dns_get_record("php.net", DNS_ANY, $authns, $addtl);
echo "Result = ";
var_dump($result);
echo "Auth NS = ";
var_dump($authns);
echo "Additional = ";
var_dump($addtl);

我得到以下输出:

---snipped---
Auth NS =

null

Additional =

null

为什么authns和其他记录为空?

我在Ubuntu 13.04 64位上运行PHP 5.5.3。

2 个答案:

答案 0 :(得分:1)

如果你想要NS条记录,你应该明确要求它们。

当您向本地递归服务器发送ANY请求时,您将只获取当时递归服务器缓存中的记录,但如果没有此类记录,则查询将触发上游{{ 1}}向权威服务器请求该域。

此外,在ANY查询中,所有返回的记录都可以在“答案”部分找到,而不是在“权限”部分。

答案 1 :(得分:0)

示例:

$NS=array('8.8.8.8');
$dns_NS_array=dns_get_record("google.com", DNS_NS, $NS);
print_r($dns_NS_array);

输出:

Array
(
    [0] => Array
        (
            [host] => google.com
            [class] => IN
            [ttl] => 343459
            [type] => NS
            [target] => ns1.google.com
        )

    [1] => Array
        (
            [host] => google.com
            [class] => IN
            [ttl] => 343459
            [type] => NS
            [target] => ns3.google.com
        )

    [2] => Array
        (
            [host] => google.com
            [class] => IN
            [ttl] => 343459
            [type] => NS
            [target] => ns2.google.com
        )

    [3] => Array
        (
            [host] => google.com
            [class] => IN
            [ttl] => 343459
            [type] => NS
            [target] => ns4.google.com
        )

)
相关问题