有没有办法,在PHP中哪一个更改退出节点(获取新IP)?
现在,我每10分钟左右就会获得一次新的IP ..
<?php
// Initialize cURL
$ch = curl_init();
// Set the website you would like to scrape
curl_setopt($ch, CURLOPT_URL, "http://icanhazip.com/");
curl_setopt($ch, CURLOPT_USERAGENT, '');
curl_setopt($ch, CURLOPT_REFERER, '');
curl_setopt($ch, CURLOPT_PROXY, '127.0.0.1:8118');
// Set cURL to return the results into a PHP variable
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// This executes the cURL request and places the results into a variable.
$curlResults= curl_exec($ch);
// Close curl
curl_close($ch);
// Echo the results to the screen>
echo $curlResults;
?>
答案 0 :(得分:4)
我不知道为什么人们想要关闭这个问题,但无论如何...... 这是适合我的解决方案。它会根据请求更改退出节点。
<?php
$fp = fsockopen('127.0.0.1', 9051, $errno, $errstr, 30);
$auth_code = 'YOUR_PASSWORD';
if ($fp) {
echo "Connected to TOR port<br />";
}
else {
echo "Cant connect to TOR port<br />";
}
fputs($fp, "AUTHENTICATE \"".$auth_code."\"\r\n");
$response = fread($fp, 1024);
list($code, $text) = explode(' ', $response, 2);
if ($code = '250') {
echo "Authenticated 250 OK<br />";
}
else {
echo "Authentication failed<br />";
}
fputs($fp, "SIGNAL NEWNYM\r\n");
$response = fread($fp, 1024);
list($code, $text) = explode(' ', $response, 2);
if ($code = '250') {
echo "New Identity OK<br />";
}
else {
echo "SIGNAL NEWNYM failed<br />";
die();
}
fclose($fp);
?>
答案 1 :(得分:1)
Tor已经默认每十分钟循环一次电路......
https://www.torproject.org/docs/tor-manual.html#MaxCircuitDirtiness
这与获得新的IP&#39;并不完全相同。您的IP可能会更改,但可能不会(中继选择是随机的)。请看......
https://stem.torproject.org/faq.html#how-do-i-request-a-new-identity-from-tor