dns_get_record

(PHP 5 CVS only)

dns_get_record --  ホスト名が指すDNSリソースレコードを取得する

説明

array dns_get_record ( string hostname [, int type [, array &authns, array &addtl]])

注意 This function is not implemented on Windows platforms.

Returns an array of associative arrays. Each associative array contains at minimum the following keys: host, type, class, ttl.

注意 'class' key will always be "IN" indicating an IPv4 resource record.

注意 'ttl' key will contain the TTL remaining since the last time the local nameserver queried the authoritative name server.

Depending on the value of type, the associate array will also contain one or more of the following keys: ip, pri, target, cpu, os, mname, rname, serial, refresh, retry, expire, minimum-ttl, txt.

hostname should be a valid DNS hostname such as "www.example.com". Reverse lookups can be generated using in-addr.arpa notation, but gethostbyaddr() is more suitable for the majority of reverse lookups.

By default, dns_get_record() will search for any resource records associated with hostname. To limit the query, specify the optional type parameter. type may be any one of the following: DNS_A, DNS_CNAME, DNS_HINFO, DNS_MX, DNS_NS, DNS_PTR, DNS_SOA, DNS_TXT, DNS_ALL or DNS_ANY. The default is DNS_ANY.

注意 Because of excentricities in the performance of libresolv between platforms, DNS_ANY will not always return every record, the slower DNS_ALL will collect all records more reliably.

The optional third and fourth arguments to this function, authns and addtl are passed by reference and, if given, will be populated with Resource Records for the Authoritative Name Servers, and any Additional Records respectively. See the example below.

SOA records are the largest of the returned types. 'mname' contains the name of the machine from which the resource records originated. 'rname' is the email address of the administrative contact for this zone. 'serial', 'refresh', 'retry', 'expire', and 'minimum-ttl' give the traditional SOA zone values one would expect.

注意 Per DNS standards, email addresses are given in user.host format (for example: hostmaster.example.com as opposed to hostmaster@example.com), be sure to check this value and modify if necessary before using it with a functions such as mail().

A records will contain an 'ip' key providing their IPv4 address.

MX records will conatin a 'pri' key indicating priority (preference). It will also have a 'target' key which lists the FQDN of the mail exchanger. See also dns_get_mx().

CNAME, NS, and PTR records will each contain a 'target' key giving the particular location in the DNS namespace which they refer to.

TXT records will have a 'txt' key containing the text data associated with the named resource record.

HINFO records have two parameters: 'cpu' and 'os' which describe the opperating environment of the specified host. The values are given as integers, see RFC 1010 for the meaning of these values.

例 1Using dns_get_record()

<?php
$result = dns_get_record("php.net");
print_r($result);
?>

/*
Produces ouput similar to the following:
----------------------------------------

Array
(
    [0] => Array
        (
            [host] => php.net
            [type] => MX
            [pri] => 5
            [target] => pair2.php.net
            [class] => IN
            [ttl] => 6765
        )

    [1] => Array
        (
            [host] => php.net
            [type] => A
            [ip] => 64.246.30.37
            [class] => IN
            [ttl] => 8125
        )

)
*/

Since it's very common to want the IP address of a mail server once the MX record has been resolved, dns_get_record() also returns an array in addtl which contains associate records. authns is returned as well conatining a list of authoritative name servers.

例 2dns_get_record()の例

<?php
/* Request "ANY" record for php.net, 
   and create $authns and $addtl arrays
   containing list of name servers and
   any additional records which go with
   them */
$result = dns_get_record("php.net",DNS_ANY,$authns,$addtl);
print "Result = ";
print_r($result);
print "Auth NS = ";
print_r($authns);
print "Additional = ";
print_r($addtl);
?>

/*
Produces output similar to the following:
-----------------------------------------

Result = Array
(
    [0] => Array
        (
            [host] => php.net
            [type] => MX
            [pri] => 5
            [target] => pair2.php.net
            [class] => IN
            [ttl] => 6765
        )

    [1] => Array
        (
            [host] => php.net
            [type] => A
            [ip] => 64.246.30.37
            [class] => IN
            [ttl] => 8125
        )

)
Auth NS = Array
(
    [0] => Array
        (
            [host] => php.net
            [type] => NS
            [target] => remote1.easydns.com
            [class] => IN
            [ttl] => 10722
        )

    [1] => Array
        (
            [host] => php.net
            [type] => NS
            [target] => remote2.easydns.com
            [class] => IN
            [ttl] => 10722
        )

    [2] => Array
        (
            [host] => php.net
            [type] => NS
            [target] => ns1.easydns.com
            [class] => IN
            [ttl] => 10722
        )

    [3] => Array
        (
            [host] => php.net
            [type] => NS
            [target] => ns2.easydns.com
            [class] => IN
            [ttl] => 10722
        )

)
Additional = Array
(
    [0] => Array
        (
            [host] => pair2.php.net
            [type] => A
            [ip] => 216.92.131.5
            [class] => IN
            [ttl] => 6766
        )

    [1] => Array
        (
            [host] => remote1.easydns.com
            [type] => A
            [ip] => 64.39.29.212
            [class] => IN
            [ttl] => 100384
        )

    [2] => Array
        (
            [host] => remote2.easydns.com
            [type] => A
            [ip] => 212.100.224.80
            [class] => IN
            [ttl] => 81241
        )

    [3] => Array
        (
            [host] => ns1.easydns.com
            [type] => A
            [ip] => 216.220.40.243
            [class] => IN
            [ttl] => 81241
        )

    [4] => Array
        (
            [host] => ns2.easydns.com
            [type] => A
            [ip] => 216.220.40.244
            [class] => IN
            [ttl] => 81241
        )

)
*/

dns_get_mx(), および dns_check_record()も参照してください。