PHP code example of jinomial / laravel-dns

1. Go to this page and download the library: Download jinomial/laravel-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/ */

    

jinomial / laravel-dns example snippets


'doh' => [
    'driver' => 'doh',
    'endpoint' => env('DOH_ENDPOINT', 'https://cloudflare-dns.com/dns-query'),
    'timeout' => 5.0,
],

use Jinomial\LaravelDns\Facades\Dns;

$records = Dns::query('google.com', 'A');

foreach ($records as $record) {
    echo $record->host; // "google.com"
    echo $record->data; // "142.250.xxx.xxx"
    echo $record->ttl;  // 300
}

$a    = Dns::getA('google.com');
$aaaa = Dns::getAAAA('google.com');
$mx   = Dns::getMX('google.com');
$txt  = Dns::getTXT('google.com');
$ns   = Dns::getNS('google.com');
$ptr  = Dns::getPTR('8.8.8.8');

// Cache the result for 60 seconds
$records = Dns::remember(60)->getA('google.com');

$records = Dns::socket('system')->query('google.com', 'A');

$records = Dns::query([
    ['name' => 'google.com', 'type' => 'A'],
    ['name' => 'github.com', 'type' => 'AAAA'],
]);

// Returns a DnsRecordCollection after resolving all promises
$records = Dns::socket('doh')->query($queries, null, ['async' => true]);

$record->host;   // The host name
$record->type;   // The record type (e.g., "A", "MX")
$record->ttl;    // Time to live
$record->data;   // The record value (IP, Target, etc.)
$record->class;  // Usually "IN"
$record->extras; // Array of driver-specific raw data

// V3
$ip = $response['Answer'][0]['data'];

// V4
$ip = $records->first()->data;

public function boot(): void
{
    $this->app->make(\Jinomial\LaravelDns\DnsManager::class)->extend('custom', function ($app, $name, $config) {
        return new MyCustomDriver($name, $config);
    });
}
bash
php artisan vendor:publish --provider="Jinomial\LaravelDns\DnsServiceProvider" --tag="laravel-dns-config"