PHP code example of ngfw / dnsdumpster

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

    

ngfw / dnsdumpster example snippets


namespace App\Http\Controllers;

use Ngfw\DNSDumpster\DNSDumpster;
use Illuminate\Http\JsonResponse;

class DomainController extends Controller
{
    private DNSDumpster $dnsDumpster;

    public function __construct(DNSDumpster $dnsDumpster)
    {
        $this->dnsDumpster = $dnsDumpster;
    }

    public function lookup(string $domain): JsonResponse
    {
        try {
            $data = $this->dnsDumpster->fetchData($domain);
            return response()->json($data);
        } catch (\Ngfw\DNSDumpster\Exceptions\InvalidDomainException $e) {
            return response()->json(['error' => 'Invalid domain'], 400);
        } catch (\Ngfw\DNSDumpster\Exceptions\RateLimitException $e) {
            return response()->json(['error' => 'Rate limit exceeded'], 429);
        } catch (\Ngfw\DNSDumpster\Exceptions\ApiException $e) {
            return response()->json(['error' => $e->getMessage()], 500);
        }
    }
}

use Illuminate\Support\Facades\App;

$dnsDumpster = App::make('DNSDumpster');
// or
$dnsDumpster = resolve('DNSDumpster');

// Use the service
$data = $dnsDumpster->fetchData('example.com');

$dnsDumpster = app('DNSDumpster');
$data = $dnsDumpster->fetchData('example.com');

$domainInfoPage2 = $dnsDumpster->fetchData('example.com', 2);

$freshData = $dnsDumpster->fetchData('example.com', 1, true);

// Clear cache for page 1
$dnsDumpster->clearCache('example.com', 1);

// Clear cache for all pages
$dnsDumpster->clearCache('example.com');

$domains = ['example.com', 'google.com', 'github.com'];
$result = $dnsDumpster->fetchBulkData($domains);

// Access successful results
foreach ($result['results'] as $domain => $data) {
    echo "Domain: {$domain}\n";
    print_r($data);
}

// Access errors
foreach ($result['errors'] as $domain => $error) {
    echo "Domain: {$domain} - Error: {$error['error']}\n";
}

use Ngfw\DNSDumpster\Exceptions\ConfigurationException;
use Ngfw\DNSDumpster\Exceptions\InvalidDomainException;
use Ngfw\DNSDumpster\Exceptions\RateLimitException;
use Ngfw\DNSDumpster\Exceptions\ApiException;

try {
    $data = $dnsDumpster->fetchData('example.com');
} catch (InvalidDomainException $e) {
    // Handle invalid domain
} catch (RateLimitException $e) {
    // Handle rate limit
    $statusCode = $e->getCode(); // HTTP 429
} catch (ApiException $e) {
    // Handle API errors
    $statusCode = $e->getStatusCode();
} catch (ConfigurationException $e) {
    // Handle configuration errors
}
bash
php artisan vendor:publish --tag=dnsdumpster-config
bash
# Single domain lookup
php artisan dnsdumpster:lookup example.com

# With pagination
php artisan dnsdumpster:lookup example.com --page=2

# Force refresh (bypass cache)
php artisan dnsdumpster:lookup example.com --force

# Bulk lookup
php artisan dnsdumpster:lookup "example.com,google.com,github.com" --bulk