PHP code example of palpalani / laravel-dns-deny-list-check
1. Go to this page and download the library: Download palpalani/laravel-dns-deny-list-check 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/ */
palpalani / laravel-dns-deny-list-check example snippets
use palPalani\DnsDenyListCheck\DnsDenyListCheck;
// Using the class directly
$checker = new DnsDenyListCheck();
$result = $checker->check('8.8.8.8');
// Using the facade
use palPalani\DnsDenyListCheck\DnsDenyListCheckFacade as DnsDenyListCheck;
$result = DnsDenyListCheck::check('8.8.8.8');
use palPalani\DnsDenyListCheck\DnsDenyListCheck;
// Custom server list
$customServers = [
['name' => 'Custom DNSBL', 'host' => 'custom.dnsbl.com', 'tier' => 1, 'priority' => 'critical']
];
$checker = new DnsDenyListCheck(
dnsblServers: $customServers,
timeoutSeconds: 15,
ipv6Enabled: true,
concurrentEnabled: false
);
$result = $checker->check('2001:db8::1'); // IPv6 support
// In a service provider
$this->app->bind(DnsDenyListCheck::class, function ($app) {
return new DnsDenyListCheck(
timeoutSeconds: config('dns-deny-list-check.timeout', 10)
);
});
// In a controller
public function checkIp(DnsDenyListCheck $checker, Request $request)
{
$result = $checker->check($request->ip());
return response()->json($result);
}
// For high-volume applications
$checker = new DnsDenyListCheck(
timeoutSeconds: 5, // Reduce timeout for faster responses
concurrentEnabled: true // Enable concurrent checking (when available)
);
// Cache results to avoid repeated checks
Cache::remember("dnsbl_check_{$ip}", 3600, function () use ($ip, $checker) {
return $checker->check($ip);
});
$result = DnsDenyListCheck::check($ip);
if (!$result['success']) {
Log::warning('DNSBL check failed', [
'ip' => $ip,
'error' => $result['message']
]);
// Fallback logic
return ['status' => 'unknown', 'reason' => 'DNSBL service unavailable'];
}
// Check if IP is blacklisted
$blacklisted = $result['stats']['total_listed'] > 0;