【问题标题】:How to use User's current IP address as the proxy in PHP cURL?如何在 PHP cURL 中使用用户当前的 IP 地址作为代理?
【发布时间】:2015-07-10 20:44:24
【问题描述】:

是否可以使用用户当前的 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;
}

有很多活生生的例子都在做同样的事情。例如谷歌的这两个工具

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

【问题讨论】:

  • 您为什么要这样做?您假设在用户机器的端口 80 上存在一个 http 代理。
  • 这就是问题所在,我无法决定。我知道这是可能的,但我怎么不知道。
  • 最好了解您在此处尝试实现的目标的背景信息,以便我们可以提供替代选项。
  • 您确定远程地址的 80 端口上运行了代理服务器吗?端口 80 是 Web 服务器的默认端口,而不是代理
  • 你不能只使用某人作为代理,必须有一个代理服务器运行在你在 CURLOPT_PROXY 中指定的地址

标签: php curl proxy


【解决方案1】:

不可能。虽然您可以让您的服务器使用用户的 IP 作为“源”发出一个 SYN 数据包,但来自目标机器的任何回复数据包都将发送到用户的机器,而不是您的服务器。

除非您控制目标/受害者上游的网络基础设施,否则不可能欺骗完整的 TCP 连接。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-04
    • 2017-01-10
    • 2016-06-19
    • 2012-05-18
    相关资源
    最近更新 更多