簡體   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