PHP dns_get_record() 函数获取与给定主机名关联的 DNS 资源记录。
语法
dns_get_record(hostname, type, authns, addtl, raw)
参数
hostname | 必填。 指定主机名(例如"www.yxjc123.com")。 |
type | 可选。 指定要搜索的资源记录类型。它可以是以下任意一项:
|
authns | 可选。 通过引用传递,如果给定,将使用权威名称服务器的资源记录进行填充。 |
addtl | 可选。 通过引用传递,如果给出,将填充任何附加记录。 |
row | 可选。 如果设置为 true,type 将被解释为原始 DNS 类型 ID。返回值会包含一个数据key,需要手动解析。默认值为 false。 |
返回值
返回关联数组的数组,失败时返回 false。每个关联数组至少包含以下键:
- host - 主机名。
- class - 仅返回 Internet 类记录并始终返回 IN。
- type - 记录类型。数组中的其他属性取决于 type 参数。
- ttl - 此记录剩余的"生存时间"(原始 ttl 减去自权威名称以来已过去的时间长度)服务器被查询)。
数组中的其他键取决于type参数。
示例:dns_get_record() 示例
下面的示例显示了dns_get_record()函数的用法。
<?php
$result = dns_get_record("baidu.com");
print_r($result);
?>
上述代码的输出将是:
Array
(
[0] => Array
(
[host] => baidu.com
[class] => IN
[ttl] => 2031
[type] => MX
[pri] => 20
[target] => jpmx.baidu.com
)
[1] => Array
(
[host] => baidu.com
[class] => IN
[ttl] => 2031
[type] => MX
[pri] => 20
[target] => usmx01.baidu.com
)
[2] => Array
(
[host] => baidu.com
[class] => IN
[ttl] => 2031
[type] => MX
[pri] => 20
[target] => mx50.baidu.com
)
[3] => Array
(
[host] => baidu.com
[class] => IN
[ttl] => 2031
[type] => MX
[pri] => 10
[target] => mx.maillb.baidu.com
)
[4] => Array
(
[host] => baidu.com
[class] => IN
[ttl] => 2031
[type] => MX
[pri] => 20
[target] => mx1.baidu.com
)
[5] => Array
(
[host] => baidu.com
[class] => IN
[ttl] => 2031
[type] => MX
[pri] => 15
[target] => mx.n.shifen.com
)
[6] => Array
(
[host] => baidu.com
[class] => IN
[ttl] => 3972
[type] => SOA
[mname] => dns.baidu.com
[rname] => sa.baidu.com
[serial] => 2012147728
[refresh] => 300
[retry] => 300
[expire] => 2592000
[minimum-ttl] => 7200
)
[7] => Array
(
[host] => baidu.com
[class] => IN
[ttl] => 3971
[type] => NS
[target] => ns3.baidu.com
)
[8] => Array
(
[host] => baidu.com
[class] => IN
[ttl] => 3971
[type] => NS
[target] => dns.baidu.com
)
[9] => Array
(
[host] => baidu.com
[class] => IN
[ttl] => 3971
[type] => NS
[target] => ns7.baidu.com
)
[10] => Array
(
[host] => baidu.com
[class] => IN
[ttl] => 3971
[type] => NS
[target] => ns4.baidu.com
)
[11] => Array
(
[host] => baidu.com
[class] => IN
[ttl] => 3971
[type] => NS
[target] => ns2.baidu.com
)
)
示例:使用类型参数
再考虑一个示例,说明如何使用 使用此函数输入参数。
<?php
$result = dns_get_record("baidu.com", DNS_MX);
print_r($result);
?>
上述代码的输出将是:
Array
(
[0] => Array
(
[host] => baidu.com
[class] => IN
[ttl] => 2832
[type] => MX
[pri] => 10
[target] => mx.maillb.baidu.com
)
[1] => Array
(
[host] => baidu.com
[class] => IN
[ttl] => 2832
[type] => MX
[pri] => 15
[target] => mx.n.shifen.com
)
[2] => Array
(
[host] => baidu.com
[class] => IN
[ttl] => 2832
[type] => MX
[pri] => 20
[target] => mx1.baidu.com
)
[3] => Array
(
[host] => baidu.com
[class] => IN
[ttl] => 2832
[type] => MX
[pri] => 20
[target] => jpmx.baidu.com
)
[4] => Array
(
[host] => baidu.com
[class] => IN
[ttl] => 2832
[type] => MX
[pri] => 20
[target] => mx50.baidu.com
)
[5] => Array
(
[host] => baidu.com
[class] => IN
[ttl] => 2832
[type] => MX
[pri] => 20
[target] => usmx01.baidu.com
)
)