The coolest thing in the world!!111
Actually it’s just a huge list of randomly generated email addresses. I’m trying to fill up an email box with as much spam as I can, so that I can dissect it and better design filters for my own mail server and such. With any luck the spambots will crawl my site (as they do already) and pick up on it and gorge on it for a little while. It should never ever contain any email addresses that are real.
The code is pretty neat if I say so myself. I might submit the snippets to Code Snippets… I made a couple of functions. The thing was loosely based on this script Random String Generator, but I made some much needed improvements.
The first “long but simple” function was way too long for my liking. I made a much neater solution:
function map_char($num) {
// range is 61... no validation in the function itself!
$int = $num;
$int+=48;
($int > 57) ? $int += 7 : null;
($int > 90) ? $int += 6 :null;
return chr($int);
}
True, 3 logic operations have to occur for any charachter, BUT that’s a lot better than a mean of 13 comparisons per charachter (as in the giant select case in the previous function). Since the script is so small and takes no use input I didn’t see the point in putting any validation into it.
Next snippet is to make a string of length $length…
for($i=1; $i< =$length; $i++)
{
mt_srand(make_seed());
$rand_string .= map_char(mt_rand(0,61));
}
make_seed() was nicked from the php documentation on mt_srand(). Easy enough. Then you just echo out your random strings with @spamdomain.co.uk on the end. You might also want to add failsafes so that you don’t ever echo out a real email address.
Then simply make an array with all your real email addresses in it, and run the returned random string against it using in_array();
The whole code to create the random string looks like this:
function generate_string($length)
{
global $valid_emails;
if($length>0)
{
$rand_id="";
for($i=1; $i< =$length; $i++)
{
mt_srand(make_seed());
$rand_id .= map_char(mt_rand(0,61));
}
}
if (in_array($rand_id,$valid_emails)) {
return generate_string($length);
} else {
return $rand_id;
}
}
The $valid_emails variable is an array containing all of your valid email addresses, for example:
$valid_email = Array ( "goldfish","arnold","grandma","auntyhetty" );
And so forth… I made it a global because it might make things easier in the future :p
So there we go… a spambot trap. Fantastical.