Spotlightsrule
Spotlightsrule

Reputation: 126

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'];
    }
}
?>

Upvotes: -1

Views: 1871

Answers (1)

Spotlightsrule
Spotlightsrule

Reputation: 126

Fixed code (works properly):

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

Upvotes: 2

Related Questions