dongwei8440 2015-09-24 14:38 采纳率: 100%
浏览 103
已采纳

PHP tor安装

I have this code:

<?php
$ip = '127.0.0.1';
$port = '9051';
$auth = 'PASSWORD';
$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."\"
");
    $received = fread($fp,512);
    fwrite($fp,$command."
");
    $received = fread($fp,512);
}

fclose($fp);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://whatismyip.org");
curl_setopt($ch, CURLOPT_PROXY, "127.0.0.1:9050");
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
$response = curl_exec($ch);
?>

The problem is it doesn't work. I am running on windows not linux. And I downloaded the tor browser. I understand there was supposed to be some configuration where I set a password and a port. However that did not happen during the install.

Is there anyone familiar with tor. What am I missing?

  • 写回答

2条回答 默认 最新

  • dsstjqsr631426 2015-09-24 21:55
    关注

    By default Tor does not listen on the control port, and you will also need to configure a password or specify it use CookieAuthentication. If you are going to be scripting with Tor, you may want to download the expert bundle instead of the browser bundle.

    These values need to go in the torrc file in the Tor Data directory. See the default sample torrc.

    First, generate a hashed password (note piping to more is necessary on Windows or you won't see any output):

    C:\Path\To\Tor>tor.exe --hash-password PASSWORD|more
    

    Copy the output that looks like 16:*BUNCH_OF_HEX_DIGITS*

    Next, you need to edit your config and add or uncomment the line with ControlPort 9051 and add your hashed password.

    ControlPort 9051
    HashedControlPassword 16:YOUR_HASHED_PASSWORD_HERE
    

    Then restart the daemon, make sure it is using the config file with these values, and try your code again.

    See the docs on the ControlPort and HashedControlPassword settings.

    Perhaps overkill for what you are doing, but you may also be interested in this PHP Tor library I made which you can use to interact with the Tor control port.

    Using my library your code would look like:

    <?php
    
    use Dapphp\TorUtils\ControlClient;
    use Dapphp\TorUtils\ProtocolError;
    $tc = new ControlClient();
    
    try {
        $tc->connect(); // connect to 127.0.0.1:9051
        $tc->authenticate(); // uses cookie authentication, can also use $tc->authenticate('password_here');
    } catch (\Exception $ex) {
        echo "Failed to create Tor control connection: " . $ex->getMessage() . "
    ";
        exit;
    }
    
    try {
        echo "Sending NEWNYM signal to controller...";
        $tc->signal(ControlClient::SIGNAL_NEWNYM);
        echo "OK";
    } catch (ProtocolError $pe) {
        echo $pe->getMessage();
    }
    
    $tc->quit(); // close control connection
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效