PHP Classes
elePHPant
Icontem

PHP DNS Check Tool: Check DNS records and compare record sets

Recommend this page to a friend!
  Info   View files Documentation   View files View files (48)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2018-02-06 (20 days ago) RSS 2.0 feedNot yet rated by the usersTotal: 9 This week: 9All time: 9,160 This week: 68Up
Version License PHP version Categories
dns-checker 1.0Custom (specified...7Networking, PHP 7
Description Author

This class can check DNS records and compare record sets.

It can perform lookups to DNS servers to obtain the values of record for certain domains and of certain record types.

The class can also compare sets of records obtained from different providers like DNS servers or arrays to determine the differences and see what changed.

Name: Matous Nemec <contact>
Classes: 1 package by
Country: Czech Republic Czech Republic

Details

Mesour DNS checker

  • Author
  • 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

  • With Composer

    composer require mesour/dns-checker

  • Or download source from GitHub

Usage

  1. Create instance \Mesour\DnsChecker\Providers\DnsRecordProvider:
$provider = new \Mesour\DnsChecker\Providers\DnsRecordProvider();

  1. Create instance \Mesour\DnsChecker\DnsChecker:
$checker = new \Mesour\DnsChecker\DnsChecker($provider);

  1. Get DNS record set (second parameter type have same values as parameter type 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();

Tests

Run command vendor/bin/tester tests/ -s -c tests/php.ini --colors

PHP Stan

Run command vendor/bin/phpstan analyse -l 7 -c phpstan.neon src tests

Code style

Run command vendor/bin/phpcs --standard=ruleset.xml --extensions=php,phpt --encoding=utf-8 --tab-width=4 -sp src tests

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',
    ],
]);
  Files folder image Files  
File Role Description
Files folder imagebin (3 files)
Files folder imagesrc (1 directory)
Files folder imagetests (2 files, 1 directory)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file license.md Lic. License text
Accessible without login Plain text file phpstan.neon Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file ruleset.xml Data Auxiliary data

  Files folder image Files  /  bin  
File Role Description
  Accessible without login Plain text file check-cs Data Auxiliary data
  Accessible without login Plain text file check-stan Data Auxiliary data
  Accessible without login Plain text file check-tests Data Auxiliary data

  Files folder image Files  /  src  
File Role Description
Files folder imageMesour (1 directory)

  Files folder image Files  /  src  /  Mesour  
File Role Description
Files folder imageDnsChecker (3 files, 4 directories)

  Files folder image Files  /  src  /  Mesour  /  DnsChecker  
File Role Description
Files folder imageDI (1 file)
Files folder imageDiffs (3 files)
Files folder imageProviders (4 files)
Files folder imageRecords (10 files)
  Plain text file DnsChecker.php Class Class source
  Plain text file DnsRecordRequest.php Class Class source
  Plain text file DnsRecordSet.php Class Class source

  Files folder image Files  /  src  /  Mesour  /  DnsChecker  /  DI  
File Role Description
  Plain text file DnsCheckerExtension.php Class Class source

  Files folder image Files  /  src  /  Mesour  /  DnsChecker  /  Diffs  
File Role Description
  Plain text file DnsRecordDiff.php Class Class source
  Plain text file DnsRecordSetDiff.php Class Class source
  Plain text file DnsRecordSetDiffFactory.php Class Class source

  Files folder image Files  /  src  /  Mesour  /  DnsChecker  /  Providers  
File Role Description
  Plain text file ArrayDnsRecordProvider.php Class Class source
  Plain text file DnsRecordProvider.php Class Class source
  Plain text file IDnsRecordProvider.php Class Class source
  Plain text file StaticDnsRecordProvider.php Class Class source

  Files folder image Files  /  src  /  Mesour  /  DnsChecker  /  Records  
File Role Description
  Plain text file A6Record.php Class Class source
  Plain text file AaaaDnsRecord.php Class Class source
  Plain text file CaaRecord.php Class Class source
  Plain text file DnsRecord.php Class Class source
  Plain text file DnsRecordType.php Class Class source
  Plain text file HInfoRecord.php Class Class source
  Plain text file IDnsRecord.php Class Class source
  Plain text file MxRecord.php Class Class source
  Plain text file SoaRecord.php Class Class source
  Plain text file SrvRecord.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imageMesour (1 directory)
  Accessible without login Plain text file bootstrap.php Example Example script
  Accessible without login Plain text file php.ini Data Auxiliary data

  Files folder image Files  /  tests  /  Mesour  
File Role Description
Files folder imageDnsCheckerTests (16 files)

  Files folder image Files  /  tests  /  Mesour  /  DnsCheckerTests  
File Role Description
  Plain text file A6RecordTest.phpt Class Class source
  Plain text file AaaaRecordTest.phpt Class Class source
  Plain text file ARecordTest.phpt Class Class source
  Plain text file BaseTestCase.php Class Class source
  Plain text file CaaRecordTest.phpt Class Class source
  Plain text file CNameRecordTest.phpt Class Class source
  Plain text file DnsRecordSetDiffTest.phpt Class Class source
  Plain text file DnsRecordSetTest.phpt Class Class source
  Plain text file HInfoRecordTest.phpt Class Class source
  Plain text file MergeDnsRecordSetTest.phpt Class Class source
  Plain text file MxRecordTest.phpt Class Class source
  Plain text file NsRecordTest.phpt Class Class source
  Plain text file PtrRecordTest.phpt Class Class source
  Plain text file SoaRecordTest.phpt Class Class source
  Plain text file SrvRecordTest.phpt Class Class source
  Plain text file TxtRecordTest.phpt Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:9
This week:9
All time:9,160
This week:68Up