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"锟斤拷锟斤拷锟斤拷锟斤拷也锟斤拷锟斤拷锟斤拷通锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟紻NS锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟矫碉拷锟斤拷锟斤拷锟斤拷锟节达拷锟斤拷锟斤拷锟斤拷锟斤拷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锟斤拷然锟斤拷一些锟斤拷锟斤拷锟角伙拷玫锟斤拷锟斤拷械募锟铰硷拷锟斤拷锟斤拷锟绞癸拷锟紻NS_ALL锟斤拷锟接可匡拷些锟斤拷

authns

锟斤拷锟斤拷锟矫凤拷式锟斤拷锟捷o拷锟斤拷锟叫达拷烁貌锟斤拷锟斤拷锟斤拷锟矫达拷锟斤拷锟矫碉拷锟矫斤拷锟斤拷锟斤拷录锟斤拷DNS锟斤拷锟斤拷锟斤拷锟斤拷Authoritative Name Servers锟斤拷锟斤拷锟斤拷息锟斤拷

addtl

锟斤拷锟斤拷锟矫凤拷式锟斤拷锟捷o拷锟斤拷锟斤拷锟叫达拷烁貌锟斤拷锟斤拷锟斤拷锟斤拷锟矫碉拷锟斤拷锟斤拷锟斤拷锟叫碉拷DNS锟斤拷锟斤拷锟斤拷录锟斤拷

raw

锟斤拷原锟斤拷模式锟铰o拷锟节斤拷锟叫讹拷锟斤拷牟锟窖拷锟绞憋拷锟街帮拷锟斤拷锟街恢达拷锟斤拷锟斤拷锟斤拷DNS锟斤拷锟酵o拷锟斤拷锟斤拷锟斤拷循锟斤拷锟斤拷询锟斤拷锟叫碉拷锟斤拷锟酵★拷

锟斤拷锟斤拷值

锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟揭伙拷锟斤拷锟斤拷锟斤拷锟斤拷椋拷锟斤拷失锟斤拷锟斤拷 锟斤拷锟斤拷锟斤拷失锟斤拷时锟斤拷锟斤拷 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()锟斤拷锟紻NS_ANY锟斤拷锟斤拷锟斤拷

锟斤拷锟斤拷锟斤拷锟角撅拷锟斤拷锟斤拷锟斤拷锟饺∫伙拷锟斤拷始锟斤拷锟斤拷锟斤拷锟斤拷亩锟接︼拷锟絀P锟斤拷址锟斤拷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.

锟轿硷拷