如何在PHP cURL中使用用户当前的IP地址作为代理


How to use User's current IP address as the proxy in PHP cURL?

是否可以使用用户当前的IP地址作为PHP cURL的代理地址?目前,我正在尝试以下代码,但给出请求超时错误。我用hma代理测试它,它工作正常,但当我试图使用用户的IP地址时,它在服务器的日志中给出请求时间错误。

function get_page($url){
$proxy=$_SERVER['REMOTE_ADDR'].":80";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_HEADER, 0); // return headers 0 no 1 yes
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return page 1:yes
curl_setopt($ch, CURLOPT_TIMEOUT, 40); // http request timeout 20 seconds
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Follow redirects, need this if the url changes
curl_setopt($ch, CURLOPT_MAXREDIRS, 2); //if http server gives redirection responce
curl_setopt($ch, CURLOPT_USERAGENT,
    "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7");
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt"); // cookies storage / here the changes have been made
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // false for https
curl_setopt($ch, CURLOPT_ENCODING, "gzip"); // the page encoding
$data = curl_exec($ch); // execute the http request
curl_close($ch); // close the connection
return $data;
}

有很多活生生的例子都在做同样的事情。例如这两个来自Google

的工具
  1. google.com/gwt/x
  2. developers.google.com/speed/pagespeed/insights

不可能。当你可以让你的服务器使用用户的IP作为"源"发出SYN包时,任何来自目标机器的应答包都将转到用户的机器,而不是你的服务器。

要欺骗一个完整的TCP连接是不可能的,除非你控制目标/受害者的上游网络基础设施。