PHPackages                             antedebaas/dns-parser - 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. antedebaas/dns-parser

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

antedebaas/dns-parser
=====================

Retrieve DNS records

v1.2.2(1y ago)0485MITPHPPHP ^8.0

Since Jul 15Pushed 1y agoCompare

[ Source](https://github.com/antedebaas/dns-parser)[ Packagist](https://packagist.org/packages/antedebaas/dns-parser)[ Docs](https://github.com/antedebaas/dns)[ RSS](/packages/antedebaas-dns-parser/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (4)Versions (10)Used By (0)

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

[](#retrieve-dns-records)

[![Latest Version on Packagist](https://camo.githubusercontent.com/4419d12ac9224c216d1901b7457dc73eb85a0fa139502d5794e59e4d5debfb3f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616e74656465626161732f646e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/antedebaas/dns)[![Tests](https://github.com/antedebaas/dns/actions/workflows/run-tests.yml/badge.svg)](https://github.com/antedebaas/dns/actions/workflows/run-tests.yml)[![Code style](https://github.com/antedebaas/dns/actions/workflows/php-cs-fixer.yml/badge.svg)](https://github.com/antedebaas/dns/actions/workflows/php-cs-fixer.yml)[![Total Downloads](https://camo.githubusercontent.com/1d89caade7dd6eca853c3d954c0a7475ca42a1e697ca8b447f632eac0619aa62/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616e74656465626161732f646e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/antedebaas/dns)

This package contains a class that can fetch DNS records. Its an extended version of Spatie\\DNS as they want to keep their version minimal.

```
use Ante\DnsParser\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`, `PTR`, `SOA`, `MX`, `SRV`, `TXT`, `DNSKEY`, `CAA`, `NAPTR`.

```
use Ante\DnsParser\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 `Ante\DnsParser\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 Ante\DnsParser\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 \Ante\DnsParser\Support\Factory();

// returns instance of \Ante\DnsParser\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:

- `Ante\DnsParser\Handler\Dig`
- `Ante\DnsParser\Handler\DnsGetRecord`

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

A custom handler class can be used by passing it to `useHandlers` on `Ante\DnsParser\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](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

### Security

[](#security)

If you've found a bug regarding security please mail .

Credits
-------

[](#credits)

- [Ante de Baas](https://github.com/antedebaas)
- [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

30

—

LowBetter than 64% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 61.3% 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 ~5 days

Total

8

Last Release

634d ago

Major Versions

v0.2.0-rc2 → v1.2.02024-08-18

v0.2.0-rc3 → v1.2.12024-08-19

### Community

Maintainers

![](https://www.gravatar.com/avatar/6e8cd80d29e0fa515ccf9502583ae07f71774d4ad9342e7fab8fb2e932689615?d=identicon)[epicgreen](/maintainers/epicgreen)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (174 commits)")[![Gummibeer](https://avatars.githubusercontent.com/u/6187884?v=4)](https://github.com/Gummibeer "Gummibeer (32 commits)")[![antedebaas](https://avatars.githubusercontent.com/u/5467398?v=4)](https://github.com/antedebaas "antedebaas (16 commits)")[![AdrianMrn](https://avatars.githubusercontent.com/u/12762044?v=4)](https://github.com/AdrianMrn "AdrianMrn (9 commits)")[![owenvoke](https://avatars.githubusercontent.com/u/1899334?v=4)](https://github.com/owenvoke "owenvoke (7 commits)")[![Nielsvanpach](https://avatars.githubusercontent.com/u/10651054?v=4)](https://github.com/Nielsvanpach "Nielsvanpach (4 commits)")[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (4 commits)")[![ManojKiranA](https://avatars.githubusercontent.com/u/30294553?v=4)](https://github.com/ManojKiranA "ManojKiranA (3 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 (3 commits)")[![hostep](https://avatars.githubusercontent.com/u/85479?v=4)](https://github.com/hostep "hostep (2 commits)")[![rennokki](https://avatars.githubusercontent.com/u/21983456?v=4)](https://github.com/rennokki "rennokki (2 commits)")[![jasonlfunk](https://avatars.githubusercontent.com/u/685188?v=4)](https://github.com/jasonlfunk "jasonlfunk (2 commits)")[![Fuitad](https://avatars.githubusercontent.com/u/263288?v=4)](https://github.com/Fuitad "Fuitad (2 commits)")[![SRWieZ](https://avatars.githubusercontent.com/u/1408020?v=4)](https://github.com/SRWieZ "SRWieZ (2 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (2 commits)")[![lwohn](https://avatars.githubusercontent.com/u/107246509?v=4)](https://github.com/lwohn "lwohn (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)")

---

Tags

phpdns

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[spatie/dns

Retrieve DNS records

6082.3M17](/packages/spatie-dns)[jbzoo/composer-diff

See what has changed after a composer update.

53888.9k1](/packages/jbzoo-composer-diff)[zoon/rialto

Manage Node resources from PHP

12199.4k3](/packages/zoon-rialto)

PHPackages © 2026

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