Created
January 2, 2012 01:32
-
-
Save kamermans/1548922 to your computer and use it in GitHub Desktop.
Simple DNSBL/RBL PHP function - trust me, it's better than checkdnsrr, fsock, socket_create, Net::DNSBL and Net::DNS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Simple DNSBL/RBL PHP function - trust me, it's better than checkdnsrr, fsock, socket_create, Net::DNSBL and Net::DNS | |
// Here's a [better] way to quickly check if an IP is in a DNSBL / RBL. It works on Windows and Linux, | |
// assuming nslookup is installed. It also supports timeout in seconds. | |
function ipInDnsBlacklist($ip, $server, $timeout=1) { | |
$response = array(); | |
$host = implode(".", array_reverse(explode('.', $ip))).'.'.$server.'.'; | |
$cmd = sprintf('nslookup -type=A -timeout=%d %s 2>&1', $timeout, escapeshellarg($host)); | |
@exec($cmd, $response); | |
// The first 3 lines (0-2) of output are not the DNS response | |
for ($i=3; $i<count($response); $i++) { | |
if (strpos(trim($response[$i]), 'Name:') === 0) { | |
return true; | |
} | |
} | |
return false; | |
} | |
ipInDnsBlacklist('188.163.68.29', 'dnsbl.tornevall.org'); // true | |
ipInDnsBlacklist('127.0.0.1', 'dnsbl.tornevall.org'); // false | |
?> |
You probably don't have nslookup
in your environment.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hm...
for me its not work...
any IP always FALSE