繁体   English   中英

PHP仅使用dns_record获取记录

[英]PHP Getting A Records Only Using dns_record

我正在为服务器制作IP抓取脚本,我的代码遇到了一些问题。 我只想使用dns_get_record来获取服务器的ip地址,而在默认输出中不会出现额外的膨胀。 但是,我当前的脚本在运行时显示空白输出。 和不。 我不能简单地使用gethostbyname,因为它必须与查询运行代码的服务器的wan ips兼容。 到目前为止,这是我的代码:

<?php
function test() {
    $host = "google.com";
     $result = dns_get_record("$host", DNS_A);
foreach ($result as $record) {
    echo $record['target'];
    }
}
?>

固定代码(正常工作):

function test() {
    $host = "google.com";
     $result = dns_get_record("$host", DNS_A);
foreach ($result as $record) {
    echo $record['ip'];
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM