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

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

anquanssl/dns
=============

PHP DNS utility

v0.0.4(2y ago)2351[1 PRs](https://github.com/anquanssl/dns/pulls)LGPL-2.1-or-laterPHPPHP &gt;=7.4

Since Oct 1Pushed 2y agoCompare

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

READMEChangelog (4)Dependencies (1)Versions (5)Used By (0)

DNS
===

[](#dns)

[![PHP-7.4 ](https://github.com/bluelibraries/dns/actions/workflows/build-7.4.yml/badge.svg)](https://github.com/bluelibraries/dns/actions/workflows/build-7.4.yml)[![PHP-8.0 ](https://github.com/bluelibraries/dns/actions/workflows/build-8.0.yml/badge.svg)](https://github.com/bluelibraries/dns/actions/workflows/build-8.0.yml)[![PHP-8.1 ](https://github.com/bluelibraries/dns/actions/workflows/build-8.1.yml/badge.svg)](https://github.com/bluelibraries/dns/actions/workflows/build-8.1.yml)[![PHP-8.2 ](https://github.com/bluelibraries/dns/actions/workflows/build-8.2.yml/badge.svg)](https://github.com/bluelibraries/dns/actions/workflows/build-8.2.yml)[![PHPUnit](https://github.com/bluelibraries/dns/actions/workflows/phpunit.yml/badge.svg)](https://github.com/bluelibraries/dns/actions/workflows/phpunit.yml)[![codecov](https://camo.githubusercontent.com/a69bb700655b091aaa6ca8ac3873588ad1318e63bad904e5d0ebcf64ed9caff0/68747470733a2f2f636f6465636f762e696f2f67682f626c75656c69627261726965732f646e732f6272616e63682f6d61696e2f67726170682f62616467652e7376673f746f6b656e3d4351424d5a3445444544)](https://codecov.io/gh/bluelibraries/dns)

Use certain DNS handler for DNS interrogation
---------------------------------------------

[](#use-certain-dns-handler-for-dns-interrogation)

FOR PHP &gt;= 7.4 ONLY
----------------------

[](#for-php---74-only)

**For older PHP version** we strongly suggest **[bluelibraries/php5-dns](https://github.com/bluelibraries/php5-dns)**
---------------------------------------------------------------------------------------------------------------------

[](#for-older-php-version-we-strongly-suggest-bluelibrariesphp5-dns)

**[Demo](https://gethostinfo.com/records/)**
--------------------------------------------

[](#demo)

### Example:

[](#example)

```
$records = DNS::getRecords('bluelibraries.com', RecordTypes::ANY);
print_r($records);
```

```
Array
(
    [0] => BlueLibraries\Dns\Records\Types\NS Object
        (
            [data:protected] => Array
                (
                    [host] => bluelibraries.com
                    [ttl] => 21600
                    [class] => IN
                    [type] => NS
                    [target] => ns3.instradns.com
                )
        )
    [1] => BlueLibraries\Dns\Records\Types\A Object
        (
            [data:protected] => Array
                (
                    [host] => bluelibraries.com
                    [ttl] => 21600
                    [class] => IN
                    [type] => A
                    [ip] => 198.50.252.64
                )
        )
)

```

Install via `composer`
----------------------

[](#install-via-composer)

```
composer require bluelibraries/dns

```

### This package contains **4** types which can be used for DNS interrogations

[](#this-package-contains-4-types-which-can-be-used-for-dns-interrogations)

1. **DnsGetRecord** based on `dns_get_record` PHP function
2. **Dig** based on `dig` shell command (better than `dns_get_record` and still secured)
3. **UDP** based on `raw` DNS calls using `UDP/socket` - useful for short answered queries as UDP answers might be limited to `512` bytes
4. **TCP** based on `raw` DNS calls using `TCP/socket` - this the best and is set as `default` handler

### Dns handlers comparison

[](#dns-handlers-comparison)

FeatureDNS\_GET\_RECORDDIGUDPTCP**Force timeout** limitNO**YES****YES****YES**Detect **more record types**
that are defined in **PHP**NO**YES****YES****YES**Use **custom nameserver**NO**YES****YES****YES**Handle **large responses****YES****YES**NO**YES**No need for **extra modules/packages** for running**YES**NO**YES****YES**### Dns handlers custom settings

[](#dns-handlers-custom-settings)

```
// Let's customize the DNS request handler - TCP
$dnsHandler = (new TCP())
    ->setPort(53)
    ->setNameserver('8.8.8.8')
    ->setTimeout(3) // limit execution to 3 seconds
    ->setRetries(5); // allows 5 retries if response fails

// Let's initialize the DNS records service
$dnsRecordsService = new DnsRecords($dnsHandler);

// let's get some TXT records from `bluelibraries.com`
$records = $dnsRecordsService->get('bluelibraries.com', RecordTypes::TXT);

// let's display them
print_r($records);
```

```
Array
(
    [0] => BlueLibraries\Dns\Records\Types\TXT Object
        (
            [data:protected] => Array
                (
                    [host] => bluelibraries.com
                    [ttl] => 3600
                    [class] => IN
                    [type] => TXT
                    [txt] => google-site-verification=kWtestq0tP8Ae_WJhRwUcZoqpdEkvuXJk
                )
        )
    [1] => BlueLibraries\Dns\Records\Types\TXT Object
        (
            [data:protected] => Array
                (
                    [host] => bluelibraries.com
                    [ttl] => 3600
                    [class] => IN
                    [type] => TXT
                    [txt] => 55d34914-636b-4x-b349-fdb9f2c1eaca
                )
        )
)

```

### Similar for UDP and DIG

[](#similar-for-udp-and-dig)

```
$dnsHandler = (new UDP())
    ->setPort(53)
    ->setNameserver('8.8.8.8')
    ->setTimeout(3) // limit execution to 3 seconds
    ->setRetries(5); // allows 5 retries if response fails

$dnsHandler = (new DIG())
    ->setPort(53)
    ->setNameserver('8.8.8.8')
    ->setTimeout(3) // limit execution to 3 seconds
    ->setRetries(5); // allows 5 retries if response fails
```

### DnsGetRecord - this handler has a limited number of settings

[](#dnsgetrecord---this-handler-has-a-limited-number-of-settings)

```
// DnsGetRecord allows only Timeout and Retries, but there is no control over timeout
// so the timeout may be much longer than the limit we set!
$dnsHandler = (new DnsGetRecord())
    ->setTimeout(3) // limit execution to 3 seconds
    ->setRetries(5); // allows 5 retries if response fails
```

Retrieve records examples, and more...
--------------------------------------

[](#retrieve-records-examples-and-more)

- [A](./docs/Records/a.md)
- [NS](./docs/Records/ns.md)
- [CNAME](./docs/Records/cname.md)
- [SOA](./docs/Records/soa.md)
- [PTR](./docs/Records/ptr.md)
- [HINFO](./docs/Records/hinfo.md)
- [MX](./docs/Records/mx.md)
- [TXT](./docs/Records/txt.md)
    - [SPF](./docs/Records/Txt/spf.md)
    - [DKIM](./docs/Records/Txt/dkim.md)
    - [DMARC](./docs/Records/Txt/dmarc.md)
    - [MtaSts](./docs/Records/Txt/mta-sts.md)
    - [TlsReporting](./docs/Records/Txt/tls-reporting.md)
    - [DomainVerification](./docs/Records/Txt/domain-verification.md)
- [AAAA](./docs/Records/aaaa.md)
- [SRV](./docs/Records/srv.md)
- [NAPTR](./docs/Records/naptr.md)
- [DS](./docs/Records/DnsSec/ds.md)
- [RRSIG](./docs/Records/DnsSec/rrsig.md)
- [NSEC](./docs/Records/DnsSec/nsec.md)
- [DNSKEY](./docs/Records/DnsSec/dnskey.md)
- [NSEC3PARAM](./docs/Records/DnsSec/nsec3param.md)
- [CDS](./docs/Records/DnsSec/cds.md)
- [CDNSKEY](./docs/Records/DnsSec/cdnskey.md)
- [HTTPS](./docs/Records/https.md)
- [CAA](./docs/Records/caa.md)

### Retrieve records using `dns_get_record`

[](#retrieve-records-using-dns_get_record)

```
$records = DNS::getRecords('bluelibraries.com', RecordTypes::TXT, DnsHandlerTypes::DNS_GET_RECORD);
print_r($records);
```

```
Array
(
    [0] => BlueLibraries\Dns\Records\Types\Txt\DomainVerification Object
        (
            [data:protected] => Array
                (
                    [host] => bluelibraries.com
                    [class] => IN
                    [ttl] => 0
                    [type] => TXT
                    [txt] => google-site-verification=test-636b-4a56-b349-test
                )
        )
)

```

### Retrieve records using `dig`

[](#retrieve-records-using-dig)

```
$records = DNS::getRecords('bluelibraries.com', RecordTypes::TXT, DnsHandlerTypes::DIG);
print_r($records);
```

```
Array
(
    [0] => BlueLibraries\Dns\Records\Types\Txt\DomainVerification Object
        (
            [data:protected] => Array
                (
                    [host] => bluelibraries.com
                    [class] => IN
                    [ttl] => 0
                    [type] => TXT
                    [txt] => google-site-verification=test-636b-4a56-b349-test
                )
        )
)

```

### Retrieve records using `UDP`

[](#retrieve-records-using-udp)

```
$records = DNS::getRecords('bluelibraries.com', RecordTypes::TXT, DnsHandlerTypes::UDP);
print_r($records);
```

```
Array
(
    [0] => BlueLibraries\Dns\Records\Types\Txt\DomainVerification Object
        (
            [data:protected] => Array
                (
                    [host] => bluelibraries.com
                    [class] => IN
                    [ttl] => 0
                    [type] => TXT
                    [txt] => google-site-verification=test-636b-4a56-b349-test
                )
        )
)

```

### Retrieve records using `TCP`

[](#retrieve-records-using-tcp)

```
// TCP is the default DNS handler, so if you are using it then you can skip it
$records = DNS::getRecords('bluelibraries.com', RecordTypes::TXT);
print_r($records);
```

```
Array
(
    [0] => BlueLibraries\Dns\Records\Types\Txt\DomainVerification Object
        (
            [data:protected] => Array
                (
                    [host] => bluelibraries.com
                    [class] => IN
                    [ttl] => 0
                    [type] => TXT
                    [txt] => google-site-verification=test-636b-4a56-b349-test
                )
        )
)

```

### Retrieve TXT records

[](#retrieve-txt-records)

```
$records = DNS::getRecords('bluelibraries.com', RecordTypes::TXT);
print_r($records);
```

```
Array
(
    [0] => BlueLibraries\Dns\Records\Types\Txt\DomainVerification Object
        (
            [data:protected] => Array
                (
                    [host] => bluelibraries.com
                    [ttl] => 3454
                    [class] => IN
                    [type] => TXT
                    [txt] => google-site-verification=kW9t2V_S7WjOX57zq0tP8Ae_WJhRwUcZoqpdEkvuXJk
                )
        )
    [1] => BlueLibraries\Dns\Records\Types\TXT Object
        (
            [data:protected] => Array
                (
                    [host] => bluelibraries.com
                    [ttl] => 3454
                    [class] => IN
                    [type] => TXT
                    [txt] => 55d14914-636b-4a56-b349-fdb9f2c1eaca
                )
        )
)

```

### Retrieve A (address) records

[](#retrieve-a-address-records)

```
$records = DNS::getRecords('bluelibraries.com', RecordTypes::A);
print_r($records);
```

```
Array
(
    [0] => BlueLibraries\Dns\Records\Types\A Object
        (
            [data:protected] => Array
                (
                    [host] => bluelibraries.com
                    [ttl] => 3600
                    [class] => IN
                    [type] => A
                    [ip] => 67.225.146.248
                )
        )
)

```

### Retrieve ALL records

[](#retrieve-all-records)

```
$records = DNS::getRecords('bluelibraries.com', RecordTypes::ALL, DnsHandlerTypes::DIG);
print_r($records);
```

```
Array
(
    [0] => BlueLibraries\Dns\Records\Types\NS Object
        (
            [data:protected] => Array
                (
                    [host] => bluelibraries.com
                    [ttl] => 3600
                    [class] => IN
                    [type] => NS
                    [target] => ns2.teestbluelibraries.com
                )
        )
    [1] => BlueLibraries\Dns\Records\Types\Txt\DomainVerification Object
        (
            [data:protected] => Array
                (
                    [host] => bluelibraries.com
                    [ttl] => 3600
                    [class] => IN
                    [type] => TXT
                    [txt] => google-site-verification=errre
                )
        )
    [2] => BlueLibraries\Dns\Records\Types\NS Object
        (
            [data:protected] => Array
                (
                    [host] => bluelibraries.com
                    [ttl] => 3600
                    [class] => IN
                    [type] => NS
                    [target] => tst3.bluelibraries.com
                )
        )
    [3] => BlueLibraries\Dns\Records\Types\TXT Object
        (
            [data:protected] => Array
                (
                    [host] => bluelibraries.com
                    [ttl] => 3600
                    [class] => IN
                    [type] => TXT
                    [txt] => 55d34914-636b-4tes-b349-fdb9f2c1eaca
                )
        )
    [4] => BlueLibraries\Dns\Records\Types\A Object
        (
            [data:protected] => Array
                (
                    [host] => bluelibraries.com
                    [ttl] => 3600
                    [class] => IN
                    [type] => A
                    [ip] => 67.225.146.248
                )
        )
)

```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 97.5% 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 ~54 days

Total

4

Last Release

794d ago

### Community

Maintainers

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

---

Top Contributors

[![bluelibraries](https://avatars.githubusercontent.com/u/23389528?v=4)](https://github.com/bluelibraries "bluelibraries (195 commits)")[![xiaohuilam](https://avatars.githubusercontent.com/u/6964962?v=4)](https://github.com/xiaohuilam "xiaohuilam (5 commits)")

---

Tags

phpdnsrecordsbluelibraries

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[imanghafoori/laravel-anypass

A minimal yet powerful package to help you in development.

21421.6k](/packages/imanghafoori-laravel-anypass)

PHPackages © 2026

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