dns_get_record

(PHP 5, PHP 7)

dns_get_record��ȡָ��������DNS��¼

˵��

dns_get_record ( string $hostname [, int $type = DNS_ANY [, array &$authns [, array &$addtl [, bool &$raw = false ]]]] ) : array

��ȡָ��������hostname����DNS��¼��

����

hostname

��������hostname��Ӧ����һ��DNS������Ч������������"www.example.com"��������Ҳ������ͨ���������������DNS���������������õ��������ڴ���������gethostbyaddr()�����ʺ�����������������

Note:

ÿ��DNS��׼���ʼ���ַ������user.host�����ĸ�ʽ������hostmaster.example.com������hostmaster@example.com������ʹ��mail()�������֮ǰ�������ֵ���б�Ҫ�Ļ�����Ҫ�޸ġ�

type

Ĭ������£�dns_get_record()��������������hostname��صļ�¼������ͨ������type���޶���ѯ��type��ֵ��������������е��κ�һ���� DNS_A��DNS_CNAME��DNS_HINFO��DNS_MX��DNS_NS��DNS_PTR��DNS_SOA��DNS_TXT��DNS_AAAA��DNS_SRV��DNS_NAPTR��DNS_A6��DNS_ALL����DNS_ANY��

Note:

����dns�ڸ���ƽ̨�ϱ�����Щ��һ����DNS_ANY�������Ƿ������еļ�¼��DNS_ALL��Ȼ��һЩ�����ǻ�õ����еļ�¼������ʹ��DNS_ALL���ӿɿ�Щ��

authns

�����÷�ʽ���ݣ����д�˸ò�������ô����õ��ý�����¼��DNS��������Authoritative Name Servers������Ϣ��

addtl

�����÷�ʽ���ݣ������д�˸ò���������õ��������е�DNS������¼��

raw

��ԭ��ģʽ�£��ڽ��ж���IJ�ѯ��ʱ��֮ǰ����ִֻ�������DNS���ͣ�������ѭ����ѯ���е����͡�

����ֵ

�����������һ���������飬���ʧ���� ������ʧ��ʱ���� FALSE��ÿ���������鶼���ٰ��������µ���Щ���� at minimum the following keys:

Basic DNS attributes
Attribute Meaning
host The record in the DNS namespace to which the rest of the associated data refers.
class dns_get_record() only returns Internet class records and as such this parameter will always return IN.
type String containing the record type. Additional attributes will also be contained in the resulting array dependant on the value of type. See table below.
ttl "Time To Live" remaining for this record. This will not equal the record's original ttl, but will rather equal the original ttl minus whatever length of time has passed since the authoritative name server was queried.

Other keys in associative arrays dependant on 'type'
Type Extra Columns
A ip: An IPv4 addresses in dotted decimal notation.
MX pri: Priority of mail exchanger. Lower numbers indicate greater priority. target: FQDN of the mail exchanger. See also dns_get_mx().
CNAME target: FQDN of location in DNS namespace to which the record is aliased.
NS target: FQDN of the name server which is authoritative for this hostname.
PTR target: Location within the DNS namespace to which this record points.
TXT txt: Arbitrary string data associated with this record.
HINFO cpu: IANA number designating the CPU of the machine referenced by this record. os: IANA number designating the Operating System on the machine referenced by this record. See IANA's » Operating System Names for the meaning of these values.
SOA mname: FQDN of the machine from which the resource records originated. rname: Email address of the administrative contain for this domain. serial: Serial # of this revision of the requested domain. refresh: Refresh interval (seconds) secondary name servers should use when updating remote copies of this domain. retry: Length of time (seconds) to wait after a failed refresh before making a second attempt. expire: Maximum length of time (seconds) a secondary DNS server should retain remote copies of the zone data without a successful refresh before discarding. minimum-ttl: Minimum length of time (seconds) a client can continue to use a DNS resolution before it should request a new resolution from the server. Can be overridden by individual resource records.
AAAA ipv6: IPv6 address
A6(PHP >= 5.1.0) masklen: Length (in bits) to inherit from the target specified by chain. ipv6: Address for this specific record to merge with chain. chain: Parent record to merge with ipv6 data.
SRV pri: (Priority) lowest priorities should be used first. weight: Ranking to weight which of commonly prioritized targets should be chosen at random. target and port: hostname and port where the requested service can be found. For additional information see: » RFC 2782
NAPTR order and pref: Equivalent to pri and weight above. flags, services, regex, and replacement: Parameters as defined by » RFC 2915.

������־

�汾 ˵��
5.4.0 �����˲���raw��
5.3.0 ��������windowsƽ̨��ʹ����������ˡ�
5.3.0 �ڴ˰汾֮ǰ�����������authns����ֵ�������ͬʱ����addtl��ֵ��

����

Example #1 ʹ�� dns_get_record()����

<?php
$result 
dns_get_record("php.net");
print_r($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
        )

)

Example #2 ʹ��dns_get_record()���DNS_ANY������

�������Ǿ��������ȡһ���ʼ��������Ķ�Ӧ��IP��ַ��MX��¼�Ƿ��Ѿ���Ч����ʹ��dns_get_record()����֮��addtl�ܹ�����һ����ص������¼��authns������᷵����Ȩ���������б���Ϣ��

<?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);
echo 
"Result = ";
print_r($result);
echo 
"Auth NS = ";
print_r($authns);
echo 
"Additional = ";
print_r($addtl);
?>

�������̵���������ڣ�

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
        )

)

ע��

Note:

For compatibility with versions before PHP 5.3.0 on some operating systems, try the » PEAR class » Net_DNS.

�μ�