php dns 域名解析

<?php

header("content-type:text/html;charset=utf-8");

$start = microtime(true);
$domain = 'segmentfault.com';
//把解析结果转化为小写
$rs = dns_get_record(strtolower($domain),DNS_NS);

echo json_encode($rs); echo '<br/>';

$end = microtime(true);

echo $end - $start;

如果解析成功,则返回:

[{
"host": "segmentfault.com",//主机名
"class": "IN",//只返回internet记录,因此这个参数将始终返回in
"ttl": 1013,//服务器被查询以来的时间长度
"type": "NS",//返回查询值的类型
"target": "ns3.dnsv3.com"//解析目标(我也不知道这个具体是什么)
}, {
"host": "segmentfault.com",
"class": "IN",
"ttl": 1013,
"type": "NS",
"target": "ns4.dnsv3.com"
}]

如果解析失败,返回一个空数组。

以上代码用于域名解析,可以根据返回结果验证解析是否成功

原文地址:https://www.cnblogs.com/ayanboke/p/9722127.html