result on my laptop for default script settings
(P4 2.66, 512mb ram)
200000
loaded in: 1.3158s
please tell me what you think of this? if you like it i can email it to you
(as a php file)
----------begin php code---------------
<?php
class honeyPot {
//define word lengths
var $umin;
var $umax;
var $dmin;
var $dmax;
//define address count
var $addresses;
var $userfordomain;
var $emails;
var $countrys;
function honeyPot($usermin = 3, $usermax = 15, $addresses = 10,
$userfordomain = false, $domainmin = 3, $domainmax = 15){
$this->umin = $usermin;
$this->umax = $usermax;
$this->addresses = $addresses;
$this->userfordomain = $userfordomain;
$this->dmin = $domainmin;
$this->dmax = $domainmax;
$this->countrys = array("","au","cz","andsoforth");
$this->types =
array("com","co","org","gov","mil","id","tv","cc","andsoforth");
}
function createAddressArray(){
$i=0;
$addressarray = array();
while($i<$this->addresses){
$addressarray[] = $this->makeAddress();
$i++;
}
return $addressarray;
}
function displayAddresses(){
$i=0;
$addressstring = "";
while($i<$this->addresses){
$addressstring .= $this->makeAddress() . "<br>";
$i++;
}
echo $addressstring;
return $addressstring;
}
function makeAddress(){
$user = $this->createRandString();
if($this->userfordomain == false){
$domain = $this->createRandString("domain");
}else{
$domain = $user;
}
$address = $user . "@" . $domain . "." . $this->createType();
$country = $this->createCountry();
if($country != ""){
$address .= "." . $country;
}
return $address;
}
function createRandString($type = "user"){
srand((double) microtime() * 948625);
if($type=="user"){
$length = rand($this->umin, $this->umax);
}else{
$length = rand($this->dmin, $this->dmax);
}
$string = "";
$numbersmin = 48;
$numbersmax = 57;
$lowercaselettersmin = 97;
$lowercaselettersmax = 122;
$whichset = 0;
while($length >= 0){
$set = rand(0,100);
if($set < 5){
$string .= "_";
}elseif($set < 32){
$string .= chr(rand($numbersmin, $numbersmax));
}else{
$string .= chr(rand($lowercaselettersmin, $lowercaselettersmax));
}
$length--;
}
return $string;
}
function createType(){
srand ((double) microtime() * 845676);
$tid = rand(0, count($this->types)-1);
return $this->types[$tid];
}
function createCountry(){
srand ((double) microtime() * 375797);
$cid = rand(0, count($this->countrys)-1);
return $this->countrys[$cid];
}
}
$test = new honeyPot();
print_r($test->createAddressArray());
echo "<br><br>\n\n";
$test->displayAddresses()
?>
--------end php code----------
--
Luke
"Daniel Hahler" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hello PHP-list,
>
> I'm building a script, that provides a honeypot of invalid email
> addresses for spambots.. for this I want to provide a macro for the
> templates that looks like %rand[x]-[y]%, where [x] and [y] are
> integers, that specify the length of the random script.
> My first thoughts were about the best parsing of the %rand..%-part,
> but now I came to a point, where I could also need suggestions on the
> random string generation..
> It considers very basic word generations and the only meaningful word
> I discovered was 'Java'.. *g
>
> For generation of a random string with length 1.000.000 it takes about
> 13 seconds on my xp 1600+.. that's quite a lot, imho, so suggestions
> are very welcome..
>
> the script goes here, ready to copy'n'paste:
>
> --------------------------------------------------------------
> list($low, $high) = explode(" ", microtime());
> $this->timerstart = $high + $low;
>
> function parserandstr($toparse){
> $debug = 0;
>
> $new = '';
> $ch = array(
> 'punct' => array('.', '.', '.', '..', '!', '!!', '?!'),
> 'sep' => array(', ', ' - '),
> 'vocal' => array('a', 'e', 'i', 'o', 'u'),
> 'cons_low' => array('x', 'y', 'z'),
> 'cons_norm' => array('b', 'c', 'd', 'f', 'g', 'h', 'j', 'k',
> 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w')
> );
> while ( ($pos = strpos($toparse, '%rand')) !== FALSE){
> if ($debug) echo '<br><br>$pos: ' . $pos;
> $new .= substr($toparse, 0, $pos);
> if ($debug) echo '<br>$new: "' . $new . '"';
>
> $toparse = substr($toparse, $pos + 5);
> if ($debug) echo '<br>$toparse: "' . $toparse . '"';
>
> $posclose = strpos($toparse, '%', 1);
> if ($debug) echo '<br>$posclose: "' . $posclose . '"';
> if ($posclose){
> $rlength = substr($toparse, 0, $posclose);
> if ($debug) echo '<br>$rlength: "' . $rlength . '"';
>
> $possep = strpos($rlength, '-');
> $minrlen = substr($rlength, 0, $possep);
> $maxrlen = substr($rlength, $possep + 1);
> if ($debug) echo '<br>$minrlen: "' . $minrlen . '"';
> if ($debug) echo '<br>$maxrlen: "' . $maxrlen . '"';
>
> $rlen = rand($minrlen, $maxrlen);
>
> // generate random string
> $randstr = ''; $inword = 0; $insentence = 0; $lastchar = '';
> for($j = 0; $j < $rlen; $j++){
> if ($inword > 3 && rand(0, 5) == 1) { // punctuation chars
> if (rand(0,5) > 0) $char = ' ';
> else {
> $char = $ch['punct'][rand(0, count($ch['punct'])-1)] . ' ';
> $j += strlen($char)-1;
> $insentence = 0;
> }
> $inword = 0;
> }
> else {
> if (!$lastwasvocal && rand(0, 10) > 6) { // vocals
> $char = $ch['vocal'][rand(0, count($ch['vocal'])-1)];
> $lastwasvocal = true;
> } else {
> do {
> if (rand(0, 30) > 0) // normal priority consonants
> $char = $ch['cons_norm'][rand(0, count($ch['cons_norm'])-1)];
> else $char = $ch['cons_low'][rand(0,
count($ch['cons_low'])-1)];
> } while ($char == $lastchar);
> $lastwasvocal = false;
> }
> $inword++;
> $insentence++;
> }
>
> if ($insentence == 1 || ($inword == 1 && rand(0, 30) < 10))
> $randstr .= strtoupper($char);
> else $randstr .= $char;
> $lastchar = $char;
> }
>
> $new .= $randstr;
> if ($debug) echo '<br>$new: ' . $new;
>
> $toparse = substr($toparse, $posclose + 1);
> if ($debug) echo '<br>$toparse: "' . $toparse . '"';
> } else $new .= '%rand';
> }
> return $new . $toparse;
> }
>
> function pre_dump($var, $desc=''){
> echo '<pre>::'.$desc.'::<br>'; var_dump($var); echo '</pre>';
> }
>
> #$s = parserandstr('random string comes here: '
> . '%rand10-1000%. this is a fake %rand and should not be killed..');
> $s = parserandstr('%rand200000-200000%');
> echo '<br><br>' . $s;
> echo '<br><br>' . strlen($s);
>
> list($low, $high) = explode(" ", microtime());
> $t = $high + $low;
> printf("<br>loaded in: %.4fs", $t - $this->timerstart);
> ------------------------------------------------------------
>
>
> --
> shinE!
> http://www.thequod.de ICQ#152282665
> PGP 8.0 key: http://thequod.de/danielhahler.asc
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php