php的curl選擇其他網路卡的ip來訪問網站

doublefacekill發表於2021-11-11

php無法像python的scarpy庫一樣,繫結網路卡。只有每次傳送請求時都指定ip。

function getHtml($url)
{
    ip=ip=this->ip;        
    ch=curlinit();curlsetopt(ch=curlinit();curlsetopt(ch, CURLOPT_URL, url);curlsetopt(url);curlsetopt(ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt(ch,CURLOPTREFERER,′http://weixin.sogou.com/weixin′);curlsetopt(ch,CURLOPTREFERER,′http://weixin.sogou.com/weixin′);curlsetopt(ch, CURLOPT_CONNECTTIMEOUT,10);
    curl_setopt(ch,CURLOPTTIMEOUT,10);curlsetopt(ch,CURLOPTTIMEOUT,10);curlsetopt(ch, CURLOPT_MAXREDIRS,1);
    curl_setopt(ch,CURLOPTHTTPHEADER,array("REMOTEADDR:ch,CURLOPTHTTPHEADER,array("REMOTEADDR:ip", "HTTP_X_FORWARDED_FOR: ip"));//這一段為指定ipcurlsetopt(ip"));//這一段為指定ipcurlsetopt(ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
    curl_setopt(ch,CURLOPTFOLLOWLOCATION,1);curlsetopt(ch,CURLOPTFOLLOWLOCATION,1);curlsetopt(ch, CURLOPT_HEADER, 1);
    content=curlexec(content=curlexec(ch);
    code=curlgetinfo(code=curlgetinfo(ch,CURLINFO_HTTP_CODE);
    curl_close(ch);if(ch);if(code=='404'){
        return false;
    }
    return $content;
}
本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章