Fix random proxy selection,

Force IPv4
This commit is contained in:
Pellaeon Lin 2017-02-24 14:24:22 +08:00
parent ff97fa61e1
commit 2bfc710f6d
3 changed files with 15 additions and 1532 deletions

View File

@ -103,7 +103,7 @@ class FacebookBridge extends BridgeAbstract {
*/ */
list($html, $info, $res_header, $proxy) = curlgetContents($captcha_action, $captcha_fields, true); list($html, $info, $res_header, $proxy) = curlgetContents($captcha_action, $captcha_fields, true);
if ( $info['http_code'] != 200 ) if ( $info['http_code'] != 200 )
returnServerError('Error '.$info['http_code'].$captcha_action."\nReq:\n".$res_header."\nResp:\n".$info['request_header']); returnServerError('Error '.$info['http_code'].$captcha_action."\nReq:\n".$res_header."\nResp:\n".$info['request_header']."\nProxy:\n".$proxy);
unset($_SESSION['captcha_fields']); unset($_SESSION['captcha_fields']);
$html = str_get_html($html); $html = str_get_html($html);
@ -119,7 +119,7 @@ class FacebookBridge extends BridgeAbstract {
if (!strpos($this->getInput('u'), "/")) { if (!strpos($this->getInput('u'), "/")) {
list($html, $info, $res_header, $proxy) = curlgetSimpleHTMLDOM(self::URI.urlencode($this->getInput('u')).'?_fb_noscript=1'); list($html, $info, $res_header, $proxy) = curlgetSimpleHTMLDOM(self::URI.urlencode($this->getInput('u')).'?_fb_noscript=1');
if ( $info['http_code'] != 200 ) if ( $info['http_code'] != 200 )
returnServerError('Error '.$info['http_code']."\nResp:\n".$res_header."\nReq:\n".$info['request_header']); returnServerError('Error '.print_r($info, true)."\nResp:\n".$res_header."\nReq:\n".$info['request_header']."\nProxy:\n".$proxy);
} else { } else {
list($html, $info) = curlgetSimpleHTMLDOM(self::URI.'pages/'.$this->getInput('u').'?_fb_noscript=1'); list($html, $info) = curlgetSimpleHTMLDOM(self::URI.'pages/'.$this->getInput('u').'?_fb_noscript=1');
if ( $info['http_code'] != 200 ) returnServerError('No results for this query.'); if ( $info['http_code'] != 200 ) returnServerError('No results for this query.');

View File

@ -10,11 +10,13 @@ function curlgetContents( $url, $params, $post=false){
$proxies = []; $proxies = [];
foreach($files as $file) { foreach($files as $file) {
$proxies_str = file_get_contents(__DIR__.'/../proxylist/'.$file); $proxies_str = file_get_contents(__DIR__.'/../proxylist/'.$file);
array_push($proxies, explode("\n", $proxies_str)); $proxies = array_merge($proxies, explode("\n", $proxies_str, -1));
} }
$proxy = array_rand($proxies); $proxy = $proxies[array_rand($proxies)];
curl_setopt($ch, CURLOPT_PROXY, $proxy); curl_setopt($ch, CURLOPT_PROXY, $proxy);
$proxy_d = print_r($proxy, true);
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLINFO_HEADER_OUT, 1); curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
@ -38,10 +40,18 @@ function curlgetContents( $url, $params, $post=false){
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size); $header = substr($response, 0, $header_size);
$body = substr($response, $header_size); $body = substr($response, $header_size);
if($errno = curl_errno($ch)) {
$error_message = curl_strerror($errno);
$info = "cURL error ({$errno}):\n {$error_message}";
}
curl_close($ch); curl_close($ch);
#file_put_contents(__DIR__.'/../debug/D'.date('H-i-s').'.html', $body); #file_put_contents(__DIR__.'/../debug/D'.date('H-i-s').'.html', $body);
rewind($verbose);
$verboseLog = stream_get_contents($verbose);
return array($body, $info, $header, $proxy); return array($body, $info, $header, $proxy_d);
} }
function curlgetSimpleHTMLDOM($url function curlgetSimpleHTMLDOM($url

File diff suppressed because it is too large Load Diff