PHP code example of mesour / dns-checker

1. Go to this page and download the library: Download mesour/dns-checker library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mesour / dns-checker example snippets


$provider = new \Mesour\DnsChecker\Providers\DnsRecordProvider();

$checker = new \Mesour\DnsChecker\DnsChecker($provider);

$dnsRecordSet = $checker->getDnsRecordSet('example.com', DNS_A + DNS_AAAA);

$dnsRecord = new \Mesour\DnsChecker\Records\DnsRecord('NS', 'example.com', 'ns3.example.com');
Assert::true($dnsRecordSet->hasRecord($dnsRecord));

$dnsRecord = new \Mesour\DnsChecker\Records\DnsRecord('AAAA', 'example.com', '2a00:4444:5555:6666::200e');
$nsDnsRecord = $dnsRecordSet->getMatchingRecord($dnsRecord);

$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);

$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();

$provider = new \Mesour\DnsChecker\Providers\StaticDnsRecordProvider([
	[
    	'host' => 'example.com',
    	'class' => 'IN',
    	'ttl' => 34,
    	'type' => 'A',
    	'ip' => '216.58.201.78',
    ],
]);