PHP to 安装 [英] PHP tor installation

查看:51
本文介绍了PHP to 安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码:

<?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."\"\n");
    $received = fread($fp,512);
    fwrite($fp,$command."\n");
    $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);
?>

问题是它不起作用.我在 Windows 上运行而不是在 linux 上运行.我下载了tor浏览器.我知道应该有一些配置,我设置了密码和端口.但是在安装过程中并没有发生这种情况.

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.

有熟悉tor的人吗?我错过了什么?

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

推荐答案

默认情况下 Tor 不侦听控制端口,您还需要配置密码或指定它使用 CookieAuthentication.如果您打算使用 Tor 编写脚本,您可能需要下载专家包而不是浏览器包.

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.

这些值需要放在 Tor Data 目录中的 torrc 文件中.请参阅默认示例 torrc.

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

首先,生成一个散列密码(注意在 Windows 上需要通过管道传递到 more 否则你将看不到任何输出):

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

复制看起来像 16:*BUNCH_OF_HEX_DIGITS*

接下来,您需要编辑您的配置并添加或取消注释带有 ControlPort 9051 的行并添加您的散列密码.

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.

请参阅有关 ControlPort 和 HashedControlPassword 设置的文档.

See the docs on the ControlPort and HashedControlPassword settings.

也许你正在做的事情有点过头了,但你可能也对这个 PHP Tor 库感兴趣您可以使用它与 Tor 控制端口进行交互.

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() . "\n";
    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

这篇关于PHP to 安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆