Skip to content

Instantly share code, notes, and snippets.

@tbreuss
Last active October 30, 2024 12:26
Show Gist options
  • Save tbreuss/74da96ff5f976ce770e6628badbd7dfc to your computer and use it in GitHub Desktop.
Save tbreuss/74da96ff5f976ce770e6628badbd7dfc to your computer and use it in GitHub Desktop.
IP Blacklist Check Script - This is a simple PHP script to lookup for blacklisted IP against multiple DNSBLs at once.
<?php // Simple PHP script to lookup for blacklisted IP against multiple DNSBLs at once. ?>
<html>
<head>
<title>DNSBL Lookup Tool - IP Blacklist Check Script</title>
</head>
<body>
<h2>IP Blacklist Check Script</h2>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<input type="text" value="" name="ip"/>
<input type="submit" value="LOOKUP"/>
</form>
<?php
/**
* The IP-address to be looked up.
* @param string $ip
*/
function dnsbllookup($ip)
{
// Add your preferred list of DNSBL's
$dnsbl_lookup = [
"dnsbl-1.uceprotect.net",
"dnsbl-2.uceprotect.net",
"dnsbl-3.uceprotect.net",
"dnsbl.dronebl.org",
"dnsbl.sorbs.net",
"zen.spamhaus.org",
"bl.spamcop.net",
"list.dsbl.org"
];
$listed = "";
if ($ip) {
$reverse_ip = implode(".", array_reverse(explode(".", $ip)));
foreach ($dnsbl_lookup as $host) {
if (checkdnsrr($reverse_ip . "." . $host . ".", "A")) {
$listed .= $reverse_ip . '.' . $host . ' <font color="red">Listed</font><br />';
}
}
}
if (empty($listed)) {
echo '"A" record was not found';
} else {
echo $listed;
}
}
if (isset($_POST['ip']) && $_POST['ip'] != null) {
$ip = $_POST['ip'];
if (filter_var($ip, FILTER_VALIDATE_IP)) {
echo dnsbllookup($ip);
} else {
echo "Please enter a valid IP";
}
}
?>
</body>
</html>
@LevinFaber
Copy link

Hey,
you should remove the sbl and xbl domains from the blocklists, since spamhaus advises the following:

"zen.spamhaus.org should be the only spamhaus.org DNSBL in your IP blocklist configuration. You should not use ZEN together with other Spamhaus IP blocklists, or with blocklists already included in our zones (such as the CBL) or you will simply be wasting DNS queries and slowing your mail queue."

@tbreuss
Copy link
Author

tbreuss commented Mar 18, 2020

Thanks @LevinFaber, I removed the sbl and xbl domains. For everyone interested here is the link https://www.spamhaus.org/zen/ with more information.

@msl-durgesh
Copy link

How we can check multiple IPs blacklist at a single hit?
Any idea , please?

@LogicalHolism
Copy link

I think you must change the system to ‘post’. Because anyone can see the users IP address from the address bar and this is quite dangerous

@tbreuss
Copy link
Author

tbreuss commented Nov 17, 2020

@TecDeveloper: Good idea, i changed the form to post.

@tbreuss
Copy link
Author

tbreuss commented Nov 17, 2020

@tbreuss
Copy link
Author

tbreuss commented Feb 15, 2021

Thanks @istiak101. I will go through your referencies and remove the UceProect RBLs.

@vielhuber
Copy link

vielhuber commented May 22, 2021

Be aware: zen.spamhaus.org marks a lot of private ip adresses, which don't send out spam and fill out regular forms.
I would recommend using primarily uceprotect level 1, 2 and also 3.

@tpsretard
Copy link

Be aware: zen.spamhaus.org marks a lot of private ip adresses, which don't send out spam and fill out regular forms.
I would recommend using primarily uceprotect level 1, 2 and also 3.

you do know that uceprotect is even worst than spamhaus.
At least spamhaus has a usable delisting process and keeps its listings up to date.

Not to mention uceprotect charges for removal even if it is not your problem.

@mondtram
Copy link

Hello.
The script works ok on A records, but actually due to my type of work i do not use A records but we add Name Servers. Can you please help me on how to change the script to work on NS.

Regards,
Mond

@heysushil
Copy link

It works perfectly. Grete work
Thank You!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment