ring-trial



If you managing a wordpress site, or any CMS, I’m sure you will encounter spam activity. It is actually a bot, or a small program that will come and visit your site, to register or post a comment. Thanks to Akismet, a default plugin that bundled together in WordPress package, that blocked most of it. Without Akismet, your life surely not like this :) There are also another WordPress plugin by Defensio.com, that claimed to be more accurate, and equipped with personalize filtering algorithm. The nice thing about Defensio, its free! :) and there is a wordpress plugin for it. To use it, you have to disable WordPress Akismet plugin. You can download the plugin here.

defensio

Theres a lot of development in spam fighting initiative. There are ProjectHoneyPotBotScout, and StopForumSpam. Through this sites, you can participate, and submit spam activity that you found so that it can be shared with others through programming API. You should take part in these initiative, to help the community in fighting spam activities. BotScout and StopForumSpam do allow access through their programming API.  Through this API, you can go there and search if any IP or email address were in their database as spammer. You can configure your custom developed application to check for this information, and block them right before form processing part of your code.

There are sample codes in PHP to connect to the API. I took some time to put these 2 API into one, therefore I can search for BotScout and StopForumSpam database in one place. For BotScout, you have to register for an API key if you want to put away the 20 searches per day limit. spamchecker

Here’s the PHP code.

$botscout_key = "ReSPMHrZ02IX4yz";
$command = $_POST['cmd'];
$email = $_POST['input'];
$ip = $_POST['input'];

switch ($command){
	case 'email':
		$request = "http://botscout.com/test/?mail=".$email."&key=".$botscout_key."";
		$result_botscout = botscout_result($request);
		$spambot = checkSpambots($email, 'EMAIL'); // stopforumspam.com
		break;
	case 'ip':
		$request = "http://botscout.com/test/?ip=".$ip."&key=".$botscout_key."";
		$result_botscout = botscout_result($request);
		$spambot = checkSpambots($ip, 'IP'); // stopforumspam.com
		break;
}

if($_POST){
	echo "

Search result for ".$_POST['input']."

"; if ($result_botscout['0'] == 'Y'){ echo "Found ".$result_botscout['2']." ".$result_botscout['1']." matches in BotScout "; }else{ echo "None on BotScout :) "; } if ($spambot['spambot'] == 'yes'){ echo "Found ".$spambot['matches']." matches in StopForumSpam. Last seen on ".$spambot['lastseen'].""; }else{ echo "None on SpamForumSpam :) "; } } function botscout_result($a){ $handle = fopen ($a, "r"); if ( $handle ){ $output = ''; while ( $line = @fgets($handle,1024) ){ $output .= $line; } $results = explode("|", $output); fclose ($handle); } $trimmed = explode("<", $results['2'] ); $results['2'] = $trimmed['0']; return $results; } // ------------------------------- function checkSpambots($mail, $cmd){ $spambot = false; //put the main domains in the array $main_domains = array('mail.ru','bigmir.net'); if($cmd == 'EMAIL'){ $xml_string = file_get_contents('http://www.stopforumspam.com/api?email='.$mail); $xml = new SimpleXMLElement($xml_string); if($xml->appears == 'yes'){ $spambot = true; } }elseif($cmd == 'IP'){ $xml_string = file_get_contents('http://www.stopforumspam.com/api?ip='.$mail); $xml = new SimpleXMLElement($xml_string); if($xml->appears == 'yes'){ $spambot = true; } } //check the main domains if there is still no spammer found, you can add more if you want in the $main_domains array if($spambot != true){ for($i = 0; $i < count($main_domains); $i++){ if(ereg($main_domains[$i],$mail) == 1){ $spambot = true; } } } $result = array("service"=>$xml->type, "matches"=>$xml->frequency, "lastseen"=>$xml->lastseen, "spambot"=>$xml->appears); return $result; } ?>

This script were modified, mainly from http://guildwarsholland.nl/phphulp/testspambot.php. I’ve stuck with XML for a while, and that code sample help me. I’m a poor code writer. Its just some hacks for me to search and check some ip and email I have in my list. Just thought it might be useful for anyone else.

No related posts.


2 Responses to “Spam Check with BotScout.com and StopForumSpam.com through PHP.”

  1. 1 mymnjoump

    Hi
    I am a newbie here.
    Glad to find this forum…as what I am looking for

  1. 1 Web-based Honeypot – participate! | NetTipsDB

Leave a Reply





Get Chitika | Premium
Eye Shadow iPhone 4 Case speckcase
Eye Shadow iPhone 4 Case by MiPhoneCase
See more iphone 4 cases
Make Your Own iPhone 4 Case speckcase
Make Your Own iPhone 4 Case by mvdesigns
More iPod touch cases

Subscribe

Subscribe to my RSS Feeds