Hi folks 👋
Recently, I published an open-source repository named gurkanbicer/getdns on GitHub.
What’s GetDNS?
Getdns is a PHP package that parses the results of the dig
command, and I use it in the GetDNS DNS Lookup tool. It provides DNS queries for hostnames. Supported DNS query types include A, AAAA, CNAME, MX, NS, TXT, SRV, and SOA. Additionally, you can query domain nameservers. You can either use random public DNS servers for lookups or configure your own public DNS servers.
This repository is part of DNS Lookup project that I created.
Installation
You can implement it in your project via composer
. The minimum PHP version requirement is 8.0.2. The package requires symfony/process:6.0.0
package to use it. I didn’t choose latest version of process package because of i wanted to support minimum PHP version. I will update it to use latest version in the next release.
composer require gurkanbicer/getdns
Usage
use Gurkanbicer\Getdns\Getdns;
use Gurkanbicer\Getdns\Exceptions\EmptyResponseException;
use Gurkanbicer\Getdns\Exceptions\InvalidDomainException;
use Symfony\Component\Process\Exception\ProcessTimedOutException;
use Symfony\Component\Process\Exception\ProcessFailedException;
$getdns = new Getdns();
try {
$getdns->setDomain("grkn.co");
$getdns->setNameserver("9.9.9.9");
$aRecords = $getdns->queryDns("A");
var_dump($aRecords);
} catch (ProcessFailedException) {
echo "The DNS query failed";
} catch (ProcessTimedOutException) {
echo "The DNS query has been timed out.";
}
Output will be like:
array(5) {
["status"]=>
string(7) "NOERROR"
["data"]=>
array(2) {
[0]=>
string(12) "188.114.97.3"
[1]=>
string(12) "188.114.96.3"
}
["query"]=>
string(1) "A"
["nameserver"]=>
string(7) "9.9.9.9"
["command"]=>
string(65) "dig +nocmd +noall +multiline +answer +comments grkn.co A @9.9.9.9"
}
If the status value is NOERROR
, you have made a successful query. Also, i suggest to catch exceptions ProcessFailedException
, ProcessTimedOutException
, InvalidDomainException
and EmptyResponseException
.
You can check the tests directory for other usage examples.
To-Do
- I will add support querying with DNSSEC and without DNSSEC.
- I will provide a free API on
getdns.com.tr
. Also, i will update the website. Because, it using old techs and old package named gurkanbicer/advanced-dns on the website.