为了解决我的项目,我在我的虚拟站(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地址吗?
提前感谢:)
答案 0 :(得分:1)
要获取不同的退出节点IP地址,请设置多个Tor客户端侦听端口9050,9051,...等等。然后在curl_init上,将代理端口更改为另一个可用的Tor客户端。
一旦耗尽了当前的Tor客户端列表,就可以重新启动它们以获得另一个退出节点。您甚至可以直接向Tor客户端发送简单的telnet命令来更改退出节点。