1. Go to this page and download the library: Download icicleio/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/ */
icicleio / dns example snippets
use Icicle\Coroutine\Coroutine;
use Icicle\Dns;
use Icicle\Loop;
$generator = function ($domain) {
try {
$ips = (yield Dns\resolve($domain));
foreach ($ips as $ip) {
echo "IP: {$ip}\n";
}
} catch (Exception $exception) {
echo "Error when executing query: {$exception->getMessage()}\n";
}
};
$coroutine = new Coroutine($generator('icicle.io'));
$coroutine->done();
Loop\run();
use Icicle\Coroutine\Coroutine;
use Icicle\Dns;
use Icicle\Loop;
use LibDNS\Messages\Message;
$coroutine = new Coroutine(Dns\execute('google.com', 'A'));
$coroutine->done(
function (Message $message) {
foreach ($message->getAnswerRecords() as $resource) {
echo "TTL: {$resource->getTTL()} Value: {$resource->getData()}\n";
}
},
function (Exception $exception) {
echo "Query failed: {$exception->getMessage()}\n";
}
);
Loop\run();
use Icicle\Dns\Executor\BasicExecutor;
$executor = new BasicExecutor('8.8.8.8');
use Icicle\Coroutine\Coroutine;
use Icicle\Dns\Executor\BasicExecutor;
use Icicle\Loop;
use LibDNS\Messages\Message;
$executor = new BasicExecutor('8.8.8.8');
$coroutine = new Coroutine($executor->execute('google.com', 'NS'));
$coroutine->done(
function (Message $message) {
foreach ($message->getAnswerRecords() as $resource) {
echo "TTL: {$resource->getTTL()} Value: {$resource->getData()}\n";
}
},
function (Exception $exception) {
echo "Query failed: {$exception->getMessage()}\n";
}
);
Loop\run();
use Icicle\Coroutine\Coroutine;
use Icicle\Dns\Executor\BasicExecutor;
use Icicle\Dns\Executor\MultiExecutor;
use Icicle\Loop;
use LibDNS\Messages\Message;
$executor = new MultiExecutor();
$executor->add(new BasicExecutor('8.8.8.8'));
$executor->add(new BasicExecutor('8.8.4.4'));
// Executor will send query to 8.8.4.4 if 8.8.8.8 does not respond.
$coroutine = new Coroutine($executor->execute('google.com', 'MX'));
$coroutine->done(
function (Message $message) {
foreach ($message->getAnswerRecords() as $resource) {
echo "TTL: {$resource->getTTL()} Value: {$resource->getData()}\n";
}
},
function (Exception $exception) {
echo "Query failed: {$exception->getMessage()}\n";
}
);
Loop\run();
use Icicle\Coroutine\Coroutine;
use Icicle\Dns;
use Icicle\Loop;
$coroutine = new Coroutine(Dns\resolve('google.com'));
$coroutine->done(
function (array $ips) {
foreach ($ips as $ip) {
echo "IP: {$ip}\n";
}
},
function (Exception $exception) {
echo "Query failed: {$exception->getMessage()}\n";
}
);
Loop\run();
use Icicle\Coroutine\Coroutine;
use Icicle\Dns\Resolver\BasicResolver;
use Icicle\Loop;
$resolver = new BasicResolver();
$coroutine = new Coroutine($resolver->resolve('google.com'));
$coroutine->done(
function (array $ips) {
foreach ($ips as $ip) {
echo "IP: {$ip}\n";
}
},
function (Exception $exception) {
echo "Query failed: {$exception->getMessage()}\n";
}
);
Loop\run();