[英]PHP Getting A Records Only Using dns_record
I am making an IP grab script for servers and I had some issues with my code. 我正在为服务器制作IP抓取脚本,我的代码遇到了一些问题。 I want to grab just the ip addresses of servers using dns_get_record without the extra bloat in the default output.
我只想使用dns_get_record来获取服务器的ip地址,而在默认输出中不会出现额外的膨胀。 However, my current script displays a blank output when ran.
但是,我当前的脚本在运行时显示空白输出。 And no.
和不。 I can't simply use gethostbyname, as it has to be compatible with querying wan ips for the server the code is running on.
我不能简单地使用gethostbyname,因为它必须与查询运行代码的服务器的wan ips兼容。 Here is my code so far:
到目前为止,这是我的代码:
<?php
function test() {
$host = "google.com";
$result = dns_get_record("$host", DNS_A);
foreach ($result as $record) {
echo $record['target'];
}
}
?>
Fixed code (works properly): 固定代码(正常工作):
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.