PHPackages                             emild/dns - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. emild/dns

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

emild/dns
=========

Retrieve DNS records

2.4.21(4y ago)032MITPHPPHP ^8.0

Since Nov 3Pushed 4y agoCompare

[ Source](https://github.com/emildayan/dns)[ Packagist](https://packagist.org/packages/emild/dns)[ Docs](https://github.com/spatie/dns)[ RSS](/packages/emild-dns/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (2)Dependencies (4)Versions (27)Used By (0)

Retrieve DNS records
====================

[](#retrieve-dns-records)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ddaa55a0316dc9808d7651869a6c332b8efb8318313949bc834a280de3491cfe/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f646e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/dns)[![Tests](https://github.com/spatie/dns/actions/workflows/tests.yml/badge.svg)](https://github.com/spatie/dns/actions/workflows/tests.yml)[![Code style](https://github.com/spatie/dns/actions/workflows/php-cs-fixer.yml/badge.svg)](https://github.com/spatie/dns/actions/workflows/php-cs-fixer.yml)[![Total Downloads](https://camo.githubusercontent.com/a533e388d4a444d2c538919b94abcfb7e48444a1abe430d3f7bbc5c6a9008793/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f646e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/dns)

This package contains a class that can fetch DNS records.

```
use Spatie\Dns\Dns;

$dns = new Dns();

$dns->getRecords('spatie.be'); // returns all available dns records

$dns->getRecords('spatie.be', 'A'); // returns only A records
```

You can use various methods to retrieve info of a record.

```
$records = $dns->getRecords('spatie.be')

$hostNameOfFirstRecord = $records[0]->host();
```

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/40c70d8a455de11aca025219313f93e0419be15b33f57cde06283aa0da5bb5ac/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f646e732e6a70673f743d31)](https://spatie.be/github-ad-click/dns)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

Installation
------------

[](#installation)

If you do not have [dig](https://linux.die.net/man/1/dig) installed you will need it.

You can install the package via composer:

```
composer require spatie/dns
```

Usage
-----

[](#usage)

The class can get these record types: `A`, `AAAA`, `CNAME`, `NS`, `SOA`, `MX`, `SRV`, `TXT`, `DNSKEY`, `CAA`, `NAPTR`.

```
use Spatie\Dns\Dns;

$dns = new Dns();

$dns->getRecords('spatie.be'); // returns all available dns records

$dns->getRecords('spatie.be', 'A'); // returns only A records
$dns->getRecords('spatie.be', ['A', 'CNAME']); // returns both A and CNAME records
$dns->getRecords('spatie.be', DNS_MX); // returns only MX records
$dns->getRecords('spatie.be', DNS_A | DNS_AAAA); // returns both A and AAAA records
```

`getRecords` will return an array with objects that implement the `Spatie\Dns\Records\Record` interface.

Working with DNS records
------------------------

[](#working-with-dns-records)

Here's how you can fetch the first A-record of a domain.

```
$ARecord = $dns->getRecords('spatie.be', 'A')[0];
```

These methods can be called on all records:

- `host()`: returns the host (`spatie.be`)
- `ttl()`: return the time to live (`900`)
- `class()`: returns the class (`IN`)
- `type()`: returns the type (`A`)

When converting a record to a string you'll get a string with all info separated with tabs.

```
(string)$ARecord // returns `spatie.be.              900     IN      A       138.197.187.74`
```

Some records have additional methods available. For example, records of type A [have an additional `ip()` method](https://github.com/spatie/dns/blob/72bf709a44e19e5d8f0bc7e6c93cf70e7a1b18f3/src/Records/A.php#L6). To know which extra methods there are, check the docblocks above [all record classes](https://github.com/spatie/dns/tree/72bf709a44e19e5d8f0bc7e6c93cf70e7a1b18f3/src/Records) in the source code.

Using a specific nameserver
---------------------------

[](#using-a-specific-nameserver)

You can get records from a specific nameserver.

```
use Spatie\Dns\Dns;

(new Dns)
    ->useNameserver('ns1.openminds.be') // use ns1.openminds.be
    ->getRecords('spatie.be');
```

Guessing a record
-----------------

[](#guessing-a-record)

When you have a string that contains a dns record, you can convert it to a `Record`

```
use \Spatie\Dns\Support\Factory();

// returns instance of \Spatie\Dns\Records\CNAME
(new Factory())->guess('www.spatie.be.       300     IN      CNAME   spatie.be.');
```

Using custom handlers
---------------------

[](#using-custom-handlers)

A `Handler` is responsible for fetching DNS records of a certain type.

By default, these handlers that ship with the package are used:

- `Spatie\Dns\Handler\Dig`
- `Spatie\Dns\Handler\DnsGetRecord`

You can create custom handlers. A valid handler is any class that extends from `Spatie\Dns\Handler\Handler`.

A custom handler class can be used by passing it to `useHandlers` on `Spatie\Dns\Dns`.

```
$results = $this->dns
    ->useHandlers([new YourCustomHandler()])
    ->getRecords('spatie.be');
```

Under the hood
--------------

[](#under-the-hood)

We will use [dig](https://wiki.ubuntuusers.de/dig/) to fetch DNS info. If it is not installed on your system, we'll call the native `dns_get_record()` function.

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Postcardware
------------

[](#postcardware)

You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.

We publish all received postcards [on our company website](https://spatie.be/en/opensource/postcards).

Credits
-------

[](#credits)

- [Harish Toshniwal](https://github.com/introwit)
- [Tom Witkowski](https://github.com/Gummibeer)
- [Freek Van der Herten](https://github.com/freekmurze)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor1

Top contributor holds 64.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~62 days

Recently: every ~6 days

Total

25

Last Release

1632d ago

Major Versions

0.0.1 → 1.0.02017-11-03

1.6.0 → 2.0.02021-05-20

PHP version history (5 changes)0.0.1PHP ^7.0

1.3.1PHP ^7.1

1.4.3PHP ^7.4

1.6.0PHP ^7.4|^8.0

2.0.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/e6c7f108921fcc361888d767b82ea328ad14ce69097d2e95a5d0e9f63cb2a9dd?d=identicon)[emild](/maintainers/emild)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (138 commits)")[![Gummibeer](https://avatars.githubusercontent.com/u/6187884?v=4)](https://github.com/Gummibeer "Gummibeer (32 commits)")[![owenvoke](https://avatars.githubusercontent.com/u/1899334?v=4)](https://github.com/owenvoke "owenvoke (7 commits)")[![AdrianMrn](https://avatars.githubusercontent.com/u/12762044?v=4)](https://github.com/AdrianMrn "AdrianMrn (5 commits)")[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (4 commits)")[![introwit](https://avatars.githubusercontent.com/u/11228182?v=4)](https://github.com/introwit "introwit (3 commits)")[![thinkstylestudio](https://avatars.githubusercontent.com/u/322368?v=4)](https://github.com/thinkstylestudio "thinkstylestudio (3 commits)")[![chapeupreto](https://avatars.githubusercontent.com/u/834048?v=4)](https://github.com/chapeupreto "chapeupreto (2 commits)")[![emildayan](https://avatars.githubusercontent.com/u/22715782?v=4)](https://github.com/emildayan "emildayan (2 commits)")[![Fuitad](https://avatars.githubusercontent.com/u/263288?v=4)](https://github.com/Fuitad "Fuitad (2 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (2 commits)")[![rennokki](https://avatars.githubusercontent.com/u/21983456?v=4)](https://github.com/rennokki "rennokki (2 commits)")[![wmouwen](https://avatars.githubusercontent.com/u/13197752?v=4)](https://github.com/wmouwen "wmouwen (1 commits)")[![aiv-damian](https://avatars.githubusercontent.com/u/132932727?v=4)](https://github.com/aiv-damian "aiv-damian (1 commits)")[![akoepcke](https://avatars.githubusercontent.com/u/5311185?v=4)](https://github.com/akoepcke "akoepcke (1 commits)")[![camlafit](https://avatars.githubusercontent.com/u/209915?v=4)](https://github.com/camlafit "camlafit (1 commits)")[![grogy](https://avatars.githubusercontent.com/u/1322983?v=4)](https://github.com/grogy "grogy (1 commits)")[![hostep](https://avatars.githubusercontent.com/u/85479?v=4)](https://github.com/hostep "hostep (1 commits)")[![jameswmcnab](https://avatars.githubusercontent.com/u/718954?v=4)](https://github.com/jameswmcnab "jameswmcnab (1 commits)")[![kennith](https://avatars.githubusercontent.com/u/871161?v=4)](https://github.com/kennith "kennith (1 commits)")

---

Tags

spatiedns

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/emild-dns/health.svg)

```
[![Health](https://phpackages.com/badges/emild-dns/health.svg)](https://phpackages.com/packages/emild-dns)
```

###  Alternatives

[spatie/dns

Retrieve DNS records

6082.3M17](/packages/spatie-dns)[spatie/laravel-package-tools

Tools for creating Laravel packages

935125.5M7.0k](/packages/spatie-laravel-package-tools)[spatie/laravel-data

Create unified resources and data transfer objects

1.7k28.9M627](/packages/spatie-laravel-data)[spatie/url

Parse, build and manipulate URL's

73914.3M97](/packages/spatie-url)[spatie/typescript-transformer

This is my package typescript-transformer

3706.5M16](/packages/spatie-typescript-transformer)[spatie/macroable

A trait to dynamically add methods to a class

72659.6M64](/packages/spatie-macroable)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
