【问题标题】:Change tor exit node programmatically (get new IP)以编程方式更改 tor 出口节点(获取新 IP)
【发布时间】:2014-09-22 06:24:11
【问题描述】:

有没有办法,在 PHP 中更改 tor 出口节点(获取新 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;

?>

【问题讨论】:

标签: php curl tor


【解决方案1】:

我不知道人们为什么要结束这个问题,但无论如何.. 这是对我有用的解决方案。它将根据请求更改出口节点。

<?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);
?>

【讨论】:

    【解决方案2】:

    Tor 已经默认每十分钟循环一次你的电路...

    https://www.torproject.org/docs/tor-manual.html#MaxCircuitDirtiness

    这与“获取新 IP”并不完全相同。您的 IP 可能会改变,但可能不会(中继选择是随机的)。请看...

    https://stem.torproject.org/faq.html#how-do-i-request-a-new-identity-from-tor

    【讨论】:

    • 是的,我知道。我需要更频繁地更改它的选项:)
    • 这个答案没有回答问题。因此不能作为答案。可能只是值得作为评论。
    猜你喜欢
    • 2010-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    相关资源
    最近更新 更多