简体   繁体   中英

PHP - Validate NS / DNS Server Ip using dns_get_record()

I am trying to validate NS / DNS Server IP provided by user, using dns_get_record() .

Code:

$site = 'google.com';
$ns = array('104.28.4.30'); // Some Ip Address not NS / DNS
echo '<pre>';
$result = dns_get_record($site, DNS_A, $ns);
print_r($result);
print_r($ns);

Output:

Array
(
[0] => Array
    (
        [host] => google.com
        [class] => IN
        [ttl] => 299
        [type] => A
        [ip] => 74.125.200.113
    )

...

[5] => Array
    (
        [host] => google.com
        [class] => IN
        [ttl] => 299
        [type] => A
        [ip] => 74.125.200.101
    )
)
Array
(
)

As I have provided some random IP but dns_get_record() seems to fetch records somehow regardless whether the provided IP is NS / DNS or not.

PS. I am aware of NET_DNS2 class but thought if there is a work around in native PHP.

The third argument to dns_get_record() is an output parameter, the initial value is ignored. It's filled in by the function with the authoritative servers for the domain.

However, DNS servers don't always return the list of authoritative servers in their responses, this is a configurable option in most nameservers (including BIND , the most common nameserver). If the server doesn't return anything in the Authority Section of the response, the array will be empty.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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