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: