mesour / dns-checker
DNS checker written in PHP for check and compare real DNS records for domain.
Fund package maintenance!
mesour
Installs: 18 246
Dependents: 1
Suggesters: 0
Security: 0
Stars: 19
Watchers: 3
Forks: 8
Open Issues: 0
Requires
- php: >=8.0
- mesour/ip-addresses: ^0.3.0
Requires (Dev)
- grifart/phpstan-oneline: ^0.4.2
- nette/di: ^3.1
- orisai/coding-standard: ^3.7
- php-parallel-lint/php-parallel-lint: ^1.3.0
- phpstan/phpstan: ^1.10.0
- phpstan/phpstan-deprecation-rules: ^1.1.0
- phpstan/phpstan-strict-rules: ^1.5
- phpunit/phpunit: ^8.5
- tracy/tracy: ^2.9.0
Suggests
- nette/di: to use class DnsCheckerExtension
This package is auto-updated.
Last update: 2024-12-05 05:30:46 UTC
README
-
DNS checker written in PHP for check and compare real DNS records for domain.
-
In
AaaaDnsRecord
is IPv6 compressed to short format. -
Problem with PHP warning:
dns_get_record(): A temporary server error occurred.
is resolved.
Install
Usage
- Create instance
\Mesour\DnsChecker\Providers\DnsRecordProvider
:
$provider = new \Mesour\DnsChecker\Providers\DnsRecordProvider();
- Create instance
\Mesour\DnsChecker\DnsChecker
:
$checker = new \Mesour\DnsChecker\DnsChecker($provider);
- Get DNS record set (second parameter
type
have same values as parametertype
for PHP function dns_get_record().):
$dnsRecordSet = $checker->getDnsRecordSet('example.com', DNS_A + DNS_AAAA);
$dnsRecordSet
contains for example:
Mesour\DnsChecker\DnsRecordSet
dnsRecords private => array (3)
| 0 => Mesour\DnsChecker\MxRecord #86b8
| | priority private => 40
| | target private => "alt3.aspmx.l.example.com" (24)
| | type private => "MX" (2)
| | name private => "example.com" (11)
| | content private => "40 alt3.aspmx.l.example.com" (27)
| | ttl private => 404
| 1 => Mesour\DnsChecker\MxRecord #5a7b
| | priority private => 50
| | target private => "alt4.aspmx.l.example.com" (24)
| | type private => "MX" (2)
| | name private => "example.com" (11)
| | content private => "50 alt4.aspmx.l.example.com" (27)
| | ttl private => 404
DnsRecordSet
- Implements
\ArrayAccess
,\Countable
and\Iterator
.
Check if exist domain record:
$dnsRecord = new \Mesour\DnsChecker\Records\DnsRecord('NS', 'example.com', 'ns3.example.com'); Assert::true($dnsRecordSet->hasRecord($dnsRecord));
Get matching DNS record:
$dnsRecord = new \Mesour\DnsChecker\Records\DnsRecord('AAAA', 'example.com', '2a00:4444:5555:6666::200e'); $nsDnsRecord = $dnsRecordSet->getMatchingRecord($dnsRecord);
More information in one DnsRecordSet
$request = new DnsRecordRequest(); $request->addFilter('example.com'); $request->addFilter('www.example.com', DNS_CNAME); // ... more lines /** @var \Mesour\DnsChecker\DnsChecker $checker */ /** @var \Mesour\DnsChecker\DnsRecordSet $records */ $records = $checker->getDnsRecordSetFromRequest($request);
Difference between two DnsRecordSets
$factory = new DnsRecordSetDiffFactory(); $expected = $this->createExpectedDnsRecordSet(); $checker = new DnsChecker(new DnsRecordProvider()); $recordSet = $checker->getDnsRecordSet('example.com'); /** @var Mesour\DnsChecker\Diffs\DnsRecordSetDiff $diff */ $diff = $factory->createDiff($expected, $recordSet); Assert::true($diff->hasDifferentRecord()); $diffs = $diff->getDiffs(); Assert::count(5, $diffs); Assert::type(Mesour\DnsChecker\Diffs\DnsRecordDiff::class, $diffs[0]); /** @var DnsRecordDiff $recordDiff */ $recordDiff = $diffs[4]; Assert::true($recordDiff->isDifferent()); // Can use this for get array of similar records with same type $recordDiff->getSimilarRecords();
Mock DNS record provider
For mock DNS provider your tests can use Mesour\DnsChecker\StaticDnsRecordProvider
or Mesour\DnsChecker\ArrayDnsRecordProvider
.
Values are as return values of PHP function dns_get_record().
$provider = new \Mesour\DnsChecker\Providers\StaticDnsRecordProvider([ [ 'host' => 'example.com', 'class' => 'IN', 'ttl' => 34, 'type' => 'A', 'ip' => '216.58.201.78', ], ]);
Development
Run command make qa
PhpUnit
Run command make phpunit
PHP Stan
Run command make phpstan
Code style
Run command make cs
Run command make csf
for fix
Parallel lint
Run command make lint