amuck-landowner

Get number of SBLs and individual IPs marked as spam

D. Strout

Resident IPv6 Proponent
Code:
<?php
/**
 * SpamHaus SBL Chcker
 * Takes domain and returns number of assigned SPLs and total blocked IPs.
 * Written by D. Strout (http://www.dstrout.net)
 */

$domain = $_REQUEST["domain"]; //Input through web
//$domain = $argv[1]; //Input through command line
if (!domainValid($domain) || strpos($domain, ".") === false)
        exit("Invalid domain name!"); //Check valid domain

$spamHaus = file_get_contents("http://www.spamhaus.org/sbl/listings/$domain"); //Retrieve Spamhaus page for this domain

$subnets = explode("</b></span>", $spamHaus); //Subnet sizes are followed by these two tags.

$totalIPs = 0;
for ($i = 1; $i < count($subnets) - 1; $i++) { //Loop through SBLs - first and last items in array aren't SBLs, don't count them.
        $subnetSize = explode("/", $subnets[$i]);
        $subnetSize = (int) $subnetSize[count($subnetSize) - 1];
        $totalIPs += pow(2, 32-$subnetSize); //Parse subnet size and calculate number of IPs. Add to $totalIPs
}

echo "SpamHaus records ".number_format($totalIPs)." IP addresses ";
echo "marked as spam under ";
echo count($subnets) - 2;
echo " SBLs assigned to $domain.\n"; //Output

function domainValid($domain) { //Domain validity checker
        return (
                preg_match("/^([a-z\d](-*[a-z\d])*)(\.([a-z\d](-*[a-z\d])*))*$/i", $domain) //Check valid characters
                && preg_match("/^.{1,253}$/", $domain) //Check valid length overall
                && preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*$/", $domain) //Check valid length in each part
        );
}
?>
 
Last edited by a moderator:

sv01

Slow but sure
just test your script ;)

Code:
SpamHaus records 459,980 IP addresses marked as spam under 40 SBLs assigned to velocity-servers.net
 

TruvisT

Server Management Specialist
Verified Provider
Linked you if that is cool, Strout. If not, let me know. Found your script cool and decided it might be nice for others and get you some publicity.
 
Top
amuck-landowner