1. Go to this page and download the library: Download utopia-php/dns library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
utopia-php / dns example snippets
topia\DNS\Adapter\Native;
use Utopia\DNS\Message\Record;
use Utopia\DNS\Resolver\Memory;
use Utopia\DNS\Server;
use Utopia\DNS\Zone;
$adapter = new Native('0.0.0.0', 5300);
$zone = new Zone(
name: 'example.test',
records: [
new Record(name: 'example.test', type: Record::TYPE_A, rdata: '192.0.2.1', ttl: 60),
new Record(name: 'www.example.test', type: Record::TYPE_CNAME, rdata: 'example.test', ttl: 60),
new Record(
name: 'example.test',
type: Record::TYPE_SOA,
rdata: 'ns1.example.test hostmaster.example.test 1 7200 1800 1209600 3600',
ttl: 60
),
]
);
$server = new Server($adapter, new Memory($zone));
$server->setDebug(true);
$server->start();
topia\DNS\Client;
use Utopia\DNS\Message;
use Utopia\DNS\Message\Question;
use Utopia\DNS\Message\Record;
$client = new Client('1.1.1.1');
$query = Message::query(
new Question('example.com', Record::TYPE_A)
);
$response = $client->query($query);
foreach ($response->answers as $answer) {
echo "{$answer->name} {$answer->ttl} {$answer->getTypeName()} {$answer->rdata}\n";
}