https://github.com/bluelibraries/php5-dns
https://github.com/bluelibraries/php5-dns
aaaa dns mx php php5 rrsig soa txt
Last synced: 25 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/bluelibraries/php5-dns
- Owner: bluelibraries
- License: lgpl-2.1
- Created: 2023-04-01T14:24:43.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-04-05T18:27:32.000Z (almost 3 years ago)
- Last Synced: 2025-02-20T10:46:49.540Z (11 months ago)
- Topics: aaaa, dns, mx, php, php5, rrsig, soa, txt
- Language: PHP
- Homepage:
- Size: 116 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# DNS
[](https://github.com/bluelibraries/php5-dns/actions/workflows/build-5.5.yml)
[](https://github.com/bluelibraries/php5-dns/actions/workflows/build-5.6.yml)
[](https://github.com/bluelibraries/php5-dns/actions/workflows/build-7.1.yml)
[](https://github.com/bluelibraries/php5-dns/actions/workflows/build-7.3.yml)
## FOR PHP >= 5.5 AND < 7.4 ONLY
## **For newer PHP version** we strongly suggest **[bluelibraries/dns](https://github.com/bluelibraries/dns)**
## Use certain DNS handler for DNS interrogation
**[Demo](https://gethostinfo.com/records/)**
### Example:
```php
$records = DNS::getRecords('bluelibraries.com', RecordTypes::ANY);
print_r($records);
```
```text
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`
```text
composer require bluelibraries/php5-dns
```
### 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
| Feature | DNS_GET_RECORD | DIG | UDP | TCP |
|---------------------------------------------------------------|----------------|---------|---------|---------|
| **Force timeout** limit | NO | **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
```php
// 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);
```
```text
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
```php
$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
```php
// 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...
- [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`
```php
$records = DNS::getRecords('bluelibraries.com', RecordTypes::TXT, DnsHandlerTypes::DNS_GET_RECORD);
print_r($records);
```
```text
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`
```php
$records = DNS::getRecords('bluelibraries.com', RecordTypes::TXT, DnsHandlerTypes::DIG);
print_r($records);
```
```text
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`
```php
$records = DNS::getRecords('bluelibraries.com', RecordTypes::TXT, DnsHandlerTypes::UDP);
print_r($records);
```
```text
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`
```php
// 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);
```
```text
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
```php
$records = DNS::getRecords('bluelibraries.com', RecordTypes::TXT);
print_r($records);
```
```text
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
```php
$records = DNS::getRecords('bluelibraries.com', RecordTypes::A);
print_r($records);
```
```text
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
```php
$records = DNS::getRecords('bluelibraries.com', RecordTypes::ALL, DnsHandlerTypes::DIG);
print_r($records);
```
```text
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
)
)
)
```