jeeven / dnslookup
A simple Laravel package to perform DNS lookups (A, AAAA, MX, NS, TXT, CNAME, SOA, etc.) using Google's DNS-over-HTTPS (DoH) resolver.
Requires
- php: ^7.4|^8.0
- illuminate/http: ^7.0|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0
- illuminate/support: ^7.0|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0
Requires (Dev)
- orchestra/testbench: ^5.0|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
- phpunit/phpunit: ^9.0|^10.0|^11.0|^12.0
README
A simple Laravel package for looking up DNS records (A, AAAA, MX, NS, TXT, CNAME, SOA, CAA, ...) for any domain, using Google's DNS-over-HTTPS (DoH) JSON API.
Requirements
- PHP 7.4 – 8.3+ (works across the range)
- Laravel 7 – 13 (works across the range; Laravel itself dictates which PHP version pairs with which Laravel version — e.g. Laravel 13 requires PHP 8.3+, older Laravel versions run fine on PHP 7.4)
Installation
composer require jeeven/dnslookup
Laravel auto-discovers the service provider and DnsLookup facade. If you've disabled package auto-discovery, register manually in config/app.php:
'providers' => [ Jeeven\DnsLookup\DnsLookupServiceProvider::class, ], 'aliases' => [ 'DnsLookup' => Jeeven\DnsLookup\Facades\DnsLookup::class, ],
Optionally publish the config file:
php artisan vendor:publish --tag=dnslookup-config
This creates config/dnslookup.php:
return [ 'endpoint' => env('DNSLOOKUP_ENDPOINT', 'https://dns.google/resolve'), 'timeout' => env('DNSLOOKUP_TIMEOUT', 5), 'cache' => [ 'enabled' => env('DNSLOOKUP_CACHE_ENABLED', true), 'store' => env('DNSLOOKUP_CACHE_STORE', null), 'ttl' => env('DNSLOOKUP_CACHE_TTL', 300), 'prefix' => 'dnslookup:', ], 'dnssec' => env('DNSLOOKUP_DNSSEC', false), ];
Usage
Facade
use Jeeven\DnsLookup\Facades\DnsLookup; // Individual record types — each returns a clean array of records DnsLookup::a('jeevenlamichhane.com.np'); DnsLookup::aaaa('jeevenlamichhane.com.np'); DnsLookup::mx('jeevenlamichhane.com.np'); DnsLookup::ns('jeevenlamichhane.com.np'); DnsLookup::txt('jeevenlamichhane.com.np'); DnsLookup::cname('www.jeevenlamichhane.com.np'); DnsLookup::soa('jeevenlamichhane.com.np'); DnsLookup::caa('jeevenlamichhane.com.np');
Each call above returns something like:
[
[
'name' => 'jeevenlamichhane.com.np',
'type' => 'A',
'ttl' => 300,
'data' => '104.21.85.84',
],
[
'name' => 'jeevenlamichhane.com.np',
'type' => 'A',
'ttl' => 300,
'data' => '172.67.203.249',
],
]
Any record type
DnsLookup::records('jeevenlamichhane.com.np', 'MX');
Just the values
DnsLookup::values('jeevenlamichhane.com.np', 'A'); // ['104.21.85.84', '172.67.203.249'] DnsLookup::ips('jeevenlamichhane.com.np'); // all A + AAAA addresses combined
Multiple record types at once
DnsLookup::all('jeevenlamichhane.com.np'); // ['A' => [...], 'AAAA' => [...], 'MX' => [...], 'NS' => [...], 'TXT' => [...], 'CNAME' => [...]] DnsLookup::all('jeevenlamichhane.com.np', ['A', 'TXT']);
Existence / status checks
DnsLookup::exists('jeevenlamichhane.com.np'); // true/false (NXDOMAIN check) DnsLookup::status('jeevenlamichhane.com.np'); // raw DNS response status code (0 = NOERROR)
Raw response
If you need the full raw resolver payload (Status, Question, Answer, Authority, Comment):
DnsLookup::lookup('jeevenlamichhane.com.np', 'NS');
Dependency injection
use Jeeven\DnsLookup\DnsLookup; class DomainController extends Controller { public function show(DnsLookup $dns, string $domain) { return $dns->all($domain); } }
Artisan command
php artisan dns:lookup jeevenlamichhane.com.np --type=A php artisan dns:lookup jeevenlamichhane.com.np --type=ALL
Example output:
A records:
+---------------------------+------+-----+----------------+
| Name | Type | TTL | Data |
+---------------------------+------+-----+----------------+
| jeevenlamichhane.com.np | A | 300 | 104.21.85.84 |
| jeevenlamichhane.com.np | A | 300 | 172.67.203.249 |
+---------------------------+------+-----+----------------+
Caching
Lookups are cached for 5 minutes by default (configurable via DNSLOOKUP_CACHE_TTL / config/dnslookup.php) to avoid repeated calls to the resolver for the same domain/type. Disable with DNSLOOKUP_CACHE_ENABLED=false.
Testing
composer test
Tests use Http::fake(), so no real network calls are made.
License
MIT