Question

i'm trying to make a tool in PHP which will simply list the components of an entered Domain's zone file. However have encountered an irritating bug, where For A/AAAA/CNAME records, it refuses to print out the data as members of the array.

            $NS = dns_get_record($url, DNS_NS);
            $MX = dns_get_record($url,DNS_MX);
            $A = dns_get_record($url,DNS_A);
            $AAAA = dns_get_record($url,DNS_AAAA);
            $CNAME = dns_get_record($url,DNS_CNAME);
            $SRV = dns_get_record($url,DNS_SRV);
            $A6 = dns_get_record($url,DNS_A6);
            $ALL = dns_get_record($url,DNS_ALL);
            $TXT = dns_get_record($url,DNS_TXT);

            //Nameservers
            echo "<br/><h4>$url's NS(Name Server) records are:</h4><br/>";
            //echo $nameserver;
            foreach ($NS as $dump) {
                echo $dump['target'], "</br>";
            }

            // MX Servers
            echo "<br/><h4>$url's MX(Mail Exchanger) records are:</h4><br/>";
            foreach ($MX as $dump) {
                echo $dump['target'], "</br>";
            }

            //A record servers

            echo "<br/><h4>$url's A records are:</h4><br/>";
            $fuck = var_dump($A);
            foreach ($A as $dump) {
                echo $dump['target'], "</br>";
            }


            //AAAA Record Servers
            echo "<br/><h4>$url's AAAA records are:</h4><br/>";
            foreach ($AAAA as $dump) {
                echo $dump['target'], "</br>";
            }

            //CNAME Record Servers
            echo "<br/><h4>$url's CNAME records are:</h4><br/>";
            foreach ($CNAME as $dump) {
                echo $dump['target'], "</br>";
            }
            //SRV Records
            echo "<br/><h4>$url's SRV records are:</h4><br/>";
            foreach ($SRV as $dump) {
                echo $dump['target'], "</br>";
            }

            //A6 Records
            echo "<br/><h4>$url's A6 records are:</h4><br/>";
            foreach ($A6 as $dump) {
                echo $dump['target'], "</br>";
            }

            //TXT records

            echo "<br/><h4>$url's TXT records are:</h4><br/>";
            foreach ($TXT as $dump) {
                echo $dump['target'], "</br>";
            }

Take for instance the A record, when i do VAR_DUMP it seems to display the information, albeit in an unbelievably ugly format. However the displayed loop seems to do nothing. I also notice that in this, information is missing (Possibly due to other records refusing to display) such as i tested a domain of mine, and the FTP. record failed to appear here.

$url is passed from $_POST['url'] which is in the format of example.com without any http or any preceding or succeeding crap.

How can i get my loops to return the full zone file in a nice ordaly fassion? Have i misunderstood how the array's are working here or have i just done something quite basic but stupid?

Was it helpful?

Solution

For an A record there is no target available, check the manual.

You only have 4 basic properties that are available to all so you have to be selective what you print in what loop. If you want to show all properties, you can also use a double loop of course:

foreach ($A as $dump) {
  foreach ($dump as $key => $value) {
    echo "{$key}: {$value}<br>";
  }
}

See an example.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top