For older PHP version we strongly suggest bluelibraries/php5-dns
$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
)
)
)
composer require bluelibraries/dns
- DnsGetRecord based on
dns_get_record
PHP function - Dig based on
dig
shell command (better thandns_get_record
and still secured) - UDP based on
raw
DNS calls usingUDP/socket
- useful for short answered queries as UDP answers might be limited to512
bytes - TCP based on
raw
DNS calls usingTCP/socket
- this the best and is set asdefault
handler
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 |
// 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
)
)
)
$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 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
- A
- NS
- CNAME
- SOA
- PTR
- HINFO
- MX
- TXT
- AAAA
- SRV
- NAPTR
- DS
- RRSIG
- NSEC
- DNSKEY
- NSEC3PARAM
- CDS
- CDNSKEY
- HTTPS
- CAA
$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
)
)
)
$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
)
)
)
$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
)
)
)
// 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
)
)
)
$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
)
)
)
$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
)
)
)
$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
)
)
)