【发布时间】:2014-03-10 23:05:00
【问题描述】:
为了解决我的项目,我在我的虚拟站 (Debian) 上安装了 tor 和 privoxy。 我找到了如何使用 curl 和 Tor 代理,但我无法在每个 curl_init() 处更改 IP 地址。
这是我的代码:
#!/usr/bin/env php
<?php
function get_url($url)
{
// ensure PHP cURL library is installed
if(function_exists('curl_init'))
{
$timestart=microtime(true);
$ip = '127.0.0.1';
$port = '9050';
$auth = 'rebootip';
$command = 'signal NEWNYM';
$fp = fsockopen($ip,$port,$error_number,$err_string,10);
if(!$fp)
{
echo "ERROR: $error_number : $err_string";
return false;
}
else
{
fwrite($fp,"AUTHENTICATE \"".$auth."\"\n");
$received = fread($fp,512);
fwrite($fp,$command."\n");
$received = fread($fp,512);
}
fclose($fp);
$ch = curl_init();
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PROXY, "127.0.0.1:9050");
curl_setopt($ch, CURLOPT_PROXYTYPE, 7);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
$response = curl_exec($ch);
$error = curl_error($ch);
print_r($response."\n");
print_r($error."\n");
}
else // PHP cURL library not installed
{
echo 'Please install PHP cURL library';
}
}
echo get_url('http://ipinfo.io/');
这是-我需要更改“tor”和“privoxy”的配置才能更改IP地址吗?
提前感谢:)
【问题讨论】:
-
你到底想在这里做什么?闻起来很腥。
-
这是我的安全课程项目。目标是在每个 curl_init() 处更改 IP 地址。
-
您能向我们解释一下您正在探索什么软件,为什么?