dtja73027 2012-11-16 20:26
浏览 119

使用代理与fsockopen

I have a Pagerank checking script that i'd like to add proxies to. I usually use Curl so im not sure exactly how to go about making the request through a proxy. I want the request to pick a random proxy from the $proxies array and use that for the request. Can anyone walk me through how this is done using this script. Thanks in advance.

$proxyauth = "username:password";

$proxies = array(
    "proxy1",
    "proxy2",
    "proxy3",
    "proxy4",
    "proxy5",
    "proxy6",
    "proxy7",
    "proxy8",
    "proxy9",
    "proxy10"
);

function check($page){
    // Open a socket to the toolbarqueries address, used by Google Toolbar
    $socket = fsockopen("toolbarqueries.google.com", 80, $errno, $errstr, 30);

    // If a connection can be established
    if($socket) {
        // Prep socket headers
        $out = "GET /tbr?client=navclient-auto&ch=".$this->checkHash($this->createHash($page))
                ."&features=Rank&q=info:".$page."&num=100&filter=0 HTTP/1.1
";
        $out .= "Host: toolbarqueries.google.com
";
        $out .= "User-Agent: Mozilla/4.0 (compatible; GoogleToolbar 2.0.114-big; Windows XP         5.1)
";
        $out .= "Connection: Close

";

        // Write settings to the socket
        fwrite($socket, $out);

        // When a response is received...
        $result = "";
        while(!feof($socket)) {
            $data = fgets($socket, 128);
            $pos = strpos($data, "Rank_");
            if($pos !== false){
                $pagerank = substr($data, $pos + 9);
                $result += $pagerank;
            }
        }
        // Close the connection
        fclose($socket);

        // Return the rank!
        return $result;
    }
}
  • 写回答

1条回答 默认 最新

  • dongpo0409 2012-11-16 21:10
    关注

    With fsockopen, instead of toolbarqueries.google.com you connect to the selected proxy. Then you send a complete URL with the GET request:

    $socket = fsockopen("proxy5", 80, $errno, $errstr, 30);
    ...
    $out = "GET http://toolbarqueries.google.com/tbr?client=..."
    

    You can still send the Host header, but you don't need it.

    评论

报告相同问题?

悬赏问题

  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败
  • ¥15 Centos7 / PETGEM