简体   繁体   中英

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. I want to grab just the ip addresses of servers using dns_get_record without the extra bloat in the default output. 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. 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'];
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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