aboutsummaryrefslogtreecommitdiffhomepage
path: root/assets/php/vendor/react/dns/examples/04-query-a-and-aaaa.php
blob: 6c46bbfe33d51ca6b2db248c753fb017f949f634 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php

use React\Dns\Model\Message;
use React\Dns\Protocol\BinaryDumper;
use React\Dns\Protocol\Parser;
use React\Dns\Query\Executor;
use React\Dns\Query\Query;
use React\EventLoop\Factory;

require __DIR__ . '/../vendor/autoload.php';

$loop = Factory::create();

$executor = new Executor($loop, new Parser(), new BinaryDumper(), null);

$name = isset($argv[1]) ? $argv[1] : 'www.google.com';

$ipv4Query = new Query($name, Message::TYPE_A, Message::CLASS_IN, time());
$ipv6Query = new Query($name, Message::TYPE_AAAA, Message::CLASS_IN, time());

$executor->query('8.8.8.8:53', $ipv4Query)->done(function (Message $message) {
    foreach ($message->answers as $answer) {
        echo 'IPv4: ' . $answer->data . PHP_EOL;
    }
}, 'printf');
$executor->query('8.8.8.8:53', $ipv6Query)->done(function (Message $message) {
    foreach ($message->answers as $answer) {
        echo 'IPv6: ' . $answer->data . PHP_EOL;
    }
}, 'printf');

$loop->run();