Net_DNS_Resolver::axfr()

Net_DNS_Resolver::axfr() -- Performs a zone transfer from a nameserver

Synopsis

require_once('Net/DNS.php');

Net_DNS_Packet Net_DNS_Resolver::axfr (string $dname [, string $class = 'IN' [, boolean $old = FALSE]])

Description

axfr() attempts a zone transfer from the nameservers specified in the Net_DNS_Resolver->nameservers array. Net_DNS_Resolver::axfr() uses the same resolver configuration as the Net_DNS_Resolver::query() method.

Most public nameservers will not allow a zone transfer by default. A zone transfer will provide a full list of DNS resource records inside of a zone file. A zone transfer will always use TCP instead of UDP queries.

For a description of the returned RR data object, see Net_DNS_RR.

Example

In the following example, debugging has been turned on and the nameserver has been configured to allow zone transfers. The most important item of note in this example is the SOA record at the beginning and end of the returned records. When a name server sends a zone transfer, the first record sent is the SOA record. The zone transfer is considered complete when the name server sends the SOA record again. This behaviour can be seen in the debug output. The resulting array returned by axfr() does not return the final SOA record.

Example 48-2. Succesful Net_DNS_Resolver::axfr() query

<?php
require_once 'Net/DNS.php';

$resolver = new Net_DNS_Resolver();
$resolver->debug = 1;
$response = $resolver->axfr('my.example.com');
echo "\n\nThe following resource records were returned from the nameserver:\n";
if (count($response)) {
  foreach ($response as $rr) {
    $rr->display();
  }
}
?>

Output:

;; axfr_start(my.example.com, IN)
;; query(my.example.com, AXFR, IN)
;; axfr_start(192.168.0.254:53)
;; sending 32 bytes
;; read_tcp: expecting 2 bytes
;; read_tcp: received 2 bytes
;; read_tcp: expecting 262 bytes
;; read_tcp: received 262 bytes
;; received 262bytes
;; HEADER SECTION
;; id = 21220
;; qr = 1    opcode = QUERY    aa = 1    tc = 0    rd = 0
;; ra = 1    rcode  = NOERROR
;; qdcount = 1  ancount = 10  nscount = 0  arcount = 0

;; QUESTION SECTION (1 record)
;;
;my.example.com.        IN      AXFR

;; ANSWER SECTION (10 records)
my.example.com.         300     IN      SOA     ns1.my.example.com. hostmaster.my.example.com. 103 3600 1800 2592000 300
my.example.com.         300     IN      NS      ns1.my.example.com.
my.example.com.         300     IN      MX      10 mx1.my.example.com.
my.example.com.         300     IN      MX      20 mx2.my.example.com.
my.example.com.         300     IN      A       192.168.0.1
mx1.my.example.com.     300     IN      A       192.168.0.2
mx2.my.example.com.     300     IN      A       192.168.0.3
server.my.example.com.  300     IN      CNAME   www.my.example.com.
www.my.example.com.     300     IN      A       192.168.0.1
my.example.com.         300     IN      SOA     ns1.my.example.com. hostmaster.my.example.com. 103 3600 1800 2592000 300

;; AUTHORITY SECTION (0 records)

;; ADDITIONAL SECTION (0 records)


The following resource records were returned from the nameserver:
my.example.com.         300     IN      SOA     ns1.my.example.com. hostmaster.my.example.com. 103 3600 1800 2592000 300
my.example.com.         300     IN      NS      ns1.my.example.com.
my.example.com.         300     IN      MX      10 mx1.my.example.com.
my.example.com.         300     IN      MX      20 mx2.my.example.com.
my.example.com.         300     IN      A       192.168.0.1
mx1.my.example.com.     300     IN      A       192.168.0.2
mx2.my.example.com.     300     IN      A       192.168.0.3
server.my.example.com.  300     IN      CNAME   www.my.example.com.
www.my.example.com.     300     IN      A       192.168.0.1

Note

This function can not be called statically.