简体   繁体   English

如何在 PHP 中回显像 nslookup 这样的 SOA 记录?

[英]How to echo SOA record like nslookup in PHP?

https://i.imgur.com/IQtyy2e.png https://i.imgur.com/IQtyy2e.png

My goal is to find current nameservers behind any HTTP Host like this.我的目标是找到像这样的任何 HTTP 主机后面的当前名称服务器。

<?php
$resolver = array( '1.1.1.1' );
$domain = 'community.cloudflare.com.';
$report = dns_get_record( $domain, DNS_SOA, $resolver );

print_r( $report );

?>

Prints印刷

Array
(
)

While it works for google.co.uk虽然它适用于 google.co.uk

Any idea how can I use PHP native function to get SOA report?知道如何使用 PHP 本机 function 获取 SOA 报告吗?

If this doesn't work then I have last option using 1.1.1.1 API which I dont want without trying first PHP way.如果这不起作用,那么我有最后一个选项使用 1.1.1.1 API,如果不尝试第一个 PHP 方式,我不想这样做。

In that case, the subdomain community.cloudflare.com(.) is part of the zone cloudflare.com.在这种情况下,子域community.cloudflare.com(.)是区域cloudflare.com. Since community.cloudflare.com(.) is not a zone (even if it could be), there are no SOA or NS records for it.由于community.cloudflare.com(.)不是一个区域(即使它可能是),所以它没有 SOA 或 NS 记录。

What you need to do is to get the SOA record or NS records from the less specific zone, which is cloudflare.com.您需要做的是从不太具体的区域获取 SOA 记录或 NS 记录,即cloudflare.com. in that case:在这种情况下:

Code代码

$domain = 'cloudflare.com.';
$report = \dns_get_record($domain, \DNS_NS);
\print_r($report);

Response回复

Array
(
    [0] => Array
        (
            [host] => cloudflare.com
            [class] => IN
            [ttl] => 21052
            [type] => NS
            [target] => ns3.cloudflare.com
        )

    [1] => Array
        (
            [host] => cloudflare.com
            [class] => IN
            [ttl] => 21052
            [type] => NS
            [target] => ns4.cloudflare.com
        )

    [2] => Array
        (
            [host] => cloudflare.com
            [class] => IN
            [ttl] => 21052
            [type] => NS
            [target] => ns5.cloudflare.com
        )

    [3] => Array
        (
            [host] => cloudflare.com
            [class] => IN
            [ttl] => 21052
            [type] => NS
            [target] => ns6.cloudflare.com
        )

    [4] => Array
        (
            [host] => cloudflare.com
            [class] => IN
            [ttl] => 21052
            [type] => NS
            [target] => ns7.cloudflare.com
        )

)

A close to what I was looking for接近我正在寻找的东西

    $host = 'community.cloudflare.com';
    
    $api = "https://cloudflare-dns.com/dns-query?name=$host&type=NS";
    
    
    
                $response = wp_remote_get( $api, array(
                'timeout' => 3,
                'redirection' => 0,
                'headers' => array( "Accept" => "application/dns-json" ),
                ));
    
                $response = wp_remote_retrieve_body( $response );
                $response = json_decode( $response, true );
    
echo '<pre>';
print_r( $response );
echo '</pre>';

Output Output

Array
(
    [Status] => 0
    [TC] => 
    [RD] => 1
    [RA] => 1
    [AD] => 1
    [CD] => 
    [Question] => Array
        (
            [0] => Array
                (
                    [name] => community.cloudflare.com
                    [type] => 2
                )

        )

    [Authority] => Array
        (
            [0] => Array
                (
                    [name] => cloudflare.com
                    [type] => 6
                    [TTL] => 93
                    [data] => ns3.cloudflare.com. dns.cloudflare.com. 2036594323 10000 2400 604800 300
                )

        )

)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM