gbxyz/czds

There is no license information available for the latest version (dev-main) of this package.

PHP client for ICANN's Centralized Zone Data Service (CZDS)

dev-main 2023-07-28 07:46 UTC

This package is auto-updated.

Last update: 2024-10-28 10:32:26 UTC


README

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!

Installation

Add the library as a dependency to your project using composer:

composer require gbxyz/czds

Usage

Load the library into your code using Composer's autoload function:

require_once 'vendor/autoload.php';

Create a client object

$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.

Get a list of available zone files

This returns an array of TLDs:

$zones = $client->getZones();

This will return an array like ['foo', 'bar'].

Save a zone file to disk

$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.

Get a file descriptor for a zone file

$fh = $client->getZoneHandle($zone);

echo stream_get_contents($fh);

Get the contents of a zone file

$zone = $client->getZoneContents($zone);

echo $zone;

Get an iterator

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;
}