This repository contains a simple client library for accessing ICANN's Centralized Zone Data Service (CZDS).
All gTLDs (top-level domains such as .com or .org) provide access to their DNS zone files via the CZDS.
You will need to create a user account on the CZDS, and request access to at least one TLD, for this to be useful!
Add the library as a dependency to your project using composer
:
composer require gbxyz/czds
Load the library into your code using Composer's autoload function:
require_once 'vendor/autoload.php';
$client = new gbxyz\czds\client;
$client->login($username, $password);
The CZDS API issues authentication tokens that are valid for 24 hours. These tokens are cached locally so this method will only incur an HTTP round trip once per day.
This returns an array of TLDs:
$zones = $client->getZones();
This will return an array like ['foo', 'bar']
.
$client->saveZone($zone, '/tmp/zonefile.txt');
$zone
should be a string containing the TLD name, e.g. xyz
.
If this fails an exception will be thrown.
$fh = $client->getZoneHandle($zone);
echo stream_get_contents($fh);
$zone = $client->getZoneContents($zone);
echo $zone;
This is useful for large zones. Instead of loading the entire zone into memory, you get an object can be iterated on, which returns objects which are instances of the various Net_DNS2_RR_*
classes.
$iterator = $client->getZoneRRs($zone);
foreach ($iterator as $rr) {
printf("Owner name: %s, TTL: %u, type: %s\n", $rr->name, $rr->ttl, $rr->type);
echo (string)$rr;
}