Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

dns_get_record

Description

The dns_get_record Network for PHP fetch DNS Resource Records associated with a hostname.

Syntax

dns_get_record(
    string $hostname,
    int $type = DNS_ANY,
    array &$authoritative_name_servers = null,
    array &$additional_records = null,
    bool $raw = false
): array|false

Parameters

hostname

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.

Note: 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().

type

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

Note: Because of eccentricities 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.

authoritative_name_servers

Passed by reference and, if given, will be populated with Resource Records for the Authoritative Name Servers.

additional_records

Passed by reference and, if given, will be populated with any Additional Records.

raw

The type will be interpreted as a raw DNS type ID (the DNS_* constants cannot be used). The return value will contain a data key, which needs to be manually parsed.

Return

This function returns an array of associative arrays, or false on failure. Each associative array contains at minimum the following keys:

AttributeDescription
hostThe record in the DNS namespace to which the rest of the associated data refers.
classdns_get_record() only returns Internet class records and as such this parameter will always return IN.
typeString 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.
TypeDescription
Aip: An IPv4 addresses in dotted decimal notation.
MXpri: Priority of mail exchanger. Lower numbers indicate greater priority. target: FQDN of the mail exchanger. See also dns_get_mx().
CNAMEtarget: FQDN of location in DNS namespace to which the record is aliased.
NStarget: FQDN of the name server which is authoritative for this hostname.
PTRtarget: Location within the DNS namespace to which this record points.
TXTtxt: Arbitrary string data associated with this record.
HINFOcpu: 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.
CAAflags: A one-byte bitfield; currently only bit 0 is defined, meaning 'critical'; other bits are reserved and should be ignored. tag: The CAA tag name (alphanumeric ASCII string). value: The CAA tag value (binary string, may use subformats). For additional information see: RFC 6844
SOAmname: FQDN of the machine from which the resource records originated. rname: Email address of the administrative contact 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.
AAAAipv6: IPv6 address
A6masklen: 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.
SRVpri: (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
NAPTRorder and pref: Equivalent to pri and weight above. flags, services, regex, and replacement: Parameters as defined by RFC 2915.

Examples

1 · hostname

<?

$hostname = "php.net";

$return = dns_get_record($hostname);

print_r($return);

?>
Array
(
    [0] => Array
        (
            [host] => php.net
            [class] => IN
            [ttl] => 300
            [type] => AAAA
            [ipv6] => 2a02:cb40:200::1ad
        )

    [1] => Array
        (
            [host] => php.net
            [class] => IN
            [ttl] => 300
            [type] => TXT
            [txt] => v=spf1 ip4:140.211.15.143 ip4:45.112.84.5 ip4:142.93.197.176 ip6:2604:a880:400:d0::1c74:1001 ip6:2a02:cb43:8000::1102 ip4:157.90.121.187 ip6:2a01:4f8:1c1e:416d::1 ~all
            [entries] => Array
                (
                    [0] => v=spf1 ip4:140.211.15.143 ip4:45.112.84.5 ip4:142.93.197.176 ip6:2604:a880:400:d0::1c74:1001 ip6:2a02:cb43:8000::1102 ip4:157.90.121.187 ip6:2a01:4f8:1c1e:416d::1 ~all
                )

        )

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

    [3] => Array
        (
            [host] => php.net
            [class] => IN
            [ttl] => 300
            [type] => SOA
            [mname] => ns1.php.net
            [rname] => admin.easydns.com
            [serial] => 1710828062
            [refresh] => 16384
            [retry] => 2048
            [expire] => 1048576
            [minimum-ttl] => 2560
        )

    [4] => Array
        (
            [host] => php.net
            [class] => IN
            [ttl] => 300
            [type] => NS
            [target] => dns4.easydns.info
        )

    [5] => Array
        (
            [host] => php.net
            [class] => IN
            [ttl] => 300
            [type] => TXT
            [txt] => google-site-verification=R0anXzbL507wmRx5iv1S-5jN55RYVo2UYIqFP2L_k1g
            [entries] => Array
                (
                    [0] => google-site-verification=R0anXzbL507wmRx5iv1S-5jN55RYVo2UYIqFP2L_k1g
                )

        )

    [6] => Array
        (
            [host] => php.net
            [class] => IN
            [ttl] => 30
            [type] => MX
            [pri] => 0
            [target] => php-smtp4-ip4.php.net
        )

    [7] => Array
        (
            [host] => php.net
            [class] => IN
            [ttl] => 300
            [type] => A
            [ip] => 185.85.0.29
        )

    [8] => Array
        (
            [host] => php.net
            [class] => IN
            [ttl] => 300
            [type] => NS
            [target] => dns3.easydns.org
        )

    [9] => Array
        (
            [host] => php.net
            [class] => IN
            [ttl] => 300
            [type] => TXT
            [txt] => google-site-verification=kEZx29YwmdFCUifeR9miIOp-x_gvEpo_T_o9UzbilLA
            [entries] => Array
                (
                    [0] => google-site-verification=kEZx29YwmdFCUifeR9miIOp-x_gvEpo_T_o9UzbilLA
                )

        )

    [10] => Array
        (
            [host] => php.net
            [class] => IN
            [ttl] => 300
            [type] => TXT
            [txt] => _globalsign-domain-verification=YKIbqgUIt0x2vDkmdYS8TzqfqP6jyVp2fVVyJWyopw
            [entries] => Array
                (
                    [0] => _globalsign-domain-verification=YKIbqgUIt0x2vDkmdYS8TzqfqP6jyVp2fVVyJWyopw
                )

        )

    [11] => Array
        (
            [host] => php.net
            [class] => IN
            [ttl] => 300
            [type] => NS
            [target] => dns2.easydns.net
        )

)

2 · type

<?

$hostname = "php.net";
$type = DNS_A;

$return = dns_get_record($hostname, $type);

print_r($return);

?>
Array
(
    [0] => Array
        (
            [host] => php.net
            [class] => IN
            [ttl] => 300
            [type] => A
            [ip] => 185.85.0.29
        )

)
HomeMenu