|
Участник форума
Регистрация: 13.08.2008
Сообщений: 146
С нами:
9339256
Репутация:
159
|
|
Попытался написать реггер Рамблера через антикапчу.
Работает как-то нестабильно. Регается ~10-20% от того, сколько капчей распознано.
Подскажите пожалуйста, в чем может быть причина?
PHP код:
<?php
$apikey = '111111111111111111111111';
$dir = 'rambler.ru/';
//randomize function
function gen(){
$a = 'abcdefghijklmnopqrstuvwxyz1234567890';
$b = $a[mt_rand(0, 25)];
for($i=0;$i<8;$i++) $b .= $a[mt_rand(0, strlen($a)-1)];
return $b;
}
//windows-1251 to utf-8
function cp1251_to_utf8($s){
$c209 = chr(209); $c208 = chr(208); $c129 = chr(129);
$t = "";
for($i=0; $i<strlen($s); $i++){
$c=ord($s[$i]);
if ($c>=192 and $c<=239) $t.=$c208.chr($c-48);
elseif ($c>239) $t.=$c209.chr($c-112);
elseif ($c==184) $t.=$c209.$c209;
elseif ($c==168) $t.=$c208.$c129;
else $t.=$s[$i];
}
return $t;
}
//anti-captcha.com API
function recognize($filename, $apikey, $is_verbose = true, $rtimeout = 5, $mtimeout = 120, $is_phrase = 0, $is_regsense = 1, $is_numeric = 0, $min_len = 0, $max_len = 0) {
if (!file_exists($filename)){
if ($is_verbose) echo "file $filename not found\n";
return false;
}
$postdata = array('method' => 'post', 'key' => $apikey, 'file' => '@'.$filename, 'phrase' => $is_phrase, 'regsense' => $is_regsense, 'numeric' => $is_numeric, 'min_len' => $min_len, 'max_len' => $max_len);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.anti-captcha.com/in.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
$result = curl_exec($ch);
if (curl_errno($ch)){
if ($is_verbose) echo "CURL returned error: ".curl_error($ch)."\n";
return false;
}
curl_close($ch);
if (strpos($result, "ERROR")!==false){
if ($is_verbose) echo "server returned error: $result\n";
return false;
}else{
$ex = explode("|", $result);
$captcha_id = $ex[1];
if ($is_verbose) echo "captcha sent, got captcha ID $captcha_id\n";
$waittime = 0;
if ($is_verbose) echo "waiting for $rtimeout seconds\n";
sleep($rtimeout);
while(true){
$result = file_get_contents('http://anti-captcha.com/res.php?key='.$apikey.'&action=get&id='.$captcha_id);
if (strpos($result, 'ERROR')!==false){
if ($is_verbose) echo "server returned error: $result\n";
return false;
}
if ($result=="CAPCHA_NOT_READY"){
if ($is_verbose) echo "captcha is not ready yet\n";
$waittime += $rtimeout;
if ($waittime>$mtimeout){
if ($is_verbose) echo "timelimit ($mtimeout) hit\n";
break;
}
if ($is_verbose) echo "waiting for $rtimeout seconds\n";
sleep($rtimeout);
}
else{
$ex = explode('|', $result);
if (trim($ex[0])=='OK') return trim($ex[1]);
}
}
return false;
}
}
$proxy = file_get_contents('proxy.txt');
for($i=0;$i<count($proxy);$i++){
//randomize (login, firstname, lastname, password, icq nick, question, answer, bithday, gender)
$login = gen();
$firstname = gen();
$lastname = gen();
$password = gen();
$icq_nick = gen();
$questions = array('Девичья фамилия матери','Почтовый индекс Ваших родителей','Модель Вашей первой машины','Ваш любимый писатель','Кличка Вашей собаки/кошки','Профессия Вашего дедушки','Номер Вашего паспорта','Любимый контрольный вопрос');
$question = urlencode(cp1251_to_utf8($questions[mt_rand(0, count($questions)-1)]));
$answer = gen();
$bmonth = mt_rand(1,12); if ($bmonth < 10) $bmonth = '0'.$bmonth;
$bday = mt_rand(1,28);
$byear = mt_rand(1965,1995);
$gender = mt_rand(1,2);
$curl = curl_init();
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 6.0)");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_PROXY, 'http://'.$proxy[$i]); //прокси
curl_setopt($curl, CURLOPT_URL, 'http://id.rambler.ru/script/newuser.cgi');
//запрос #1
curl_setopt($curl, CURLOPT_POSTFIELDS, 'back=&step=one&login='.$login.'&firstname='.$firstname.'&lastname='.$lastname);
$s = curl_exec($curl);
//распознавание капчи
preg_match('#/captcha/(.*).jpg#', $s, $number);
$f = fopen($number[1].'.jpg', 'w-');
fputs($f, file_get_contents('http://id.rambler.ru'.$number[0]));
fclose($f);
$hash = recognize($_SERVER['DOCUMENT_ROOT'].$dir.$number[1].'.jpg', $apikey, false, 0, 1, 0, 3, 10);
//запрос #2
curl_setopt($curl, CURLOPT_URL, 'http://id.rambler.ru/script/newuser.cgi');
curl_setopt($curl, CURLOPT_POSTFIELDS, 'back=&step=two&step=one&login='.$login.'&domain=rambler.ru&firstname='.$firstname.'&lastname='.$lastname.'&password='.$password.'&password2='.$password.'&question='.$question.'&answer='.$answer.'&recoverpassword=&icq_mode=getnew&icq_nick='.$icq_nick.'&icq=&icq_passw=&bday='.$bday.'&bmonth='.$bmonth.'&byear='.$byear.'&gender='.$gender.'&number='.$number[1].'&hash='.$hash);
$s = curl_exec($curl);
//пишем в файл
if (substr_count($s, 'Поздравляем! Вы зарегистрированы на Рамблере')>0){
preg_match('#<a href="icq.cgi">(.*)</a></b>#', $s, $i);
$f = fopen('mail.txt', 'w+');
fputs($f, $login.'@rambler.ru:'.$password.':'.$i[1]."\r\n");
fclose($f);
}
//log out
curl_setopt($curl, CURLOPT_URL, 'http://id.rambler.ru/script/auth.cgi?mode=logout');
curl_exec($curl);
}
?>
Последний раз редактировалось ViP-K1LLeR; 14.03.2009 в 21:02..
|