如何以编程方式更改 Tor 出口节点以获得新 IP?

发布于 2024-08-16 08:48:32 字数 200 浏览 11 评论 0原文

我的计算机上运行着 Tor,我需要每五分钟更改一次 Tor 出口节点。 例如,如果我开始通过某个出口节点使用 Tor,那么我希望 Tor 在 5 分钟内更改为具有不同 IP 地址的出口节​​点。我该怎么做?

据我所知,Tor 正在监听本地主机上的 8051 端口。

我可以向此端口发送哪些命令来让 Tor 构建一条新链,以便我可以获得另一个 IP 地址?

I have Tor running on my computer, and I need to change the Tor exit node every five minutes.
For example, if I start using Tor via some exit node, then in 5 minutes I want Tor to change to an exit node with a different IP address. How can I do this?

Tor, as far as I know, is listening to port 8051 on localhost.

What commands can I send to this port to make Tor build a new chain, so that I can get another IP address?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

为你拒绝所有暧昧 2024-08-23 08:48:32

方法 1:HUP

sudo killall -HUP tor

然后检查您的 IP 是否已更改 with:

curl --socks5 127.0.0.1:9050 http://checkip.amazonaws.com/

在 Ubuntu 17.10 中使用 sudo apt-get install to 版本 1.6.0-5 进行测试。

需要 sudo 因为该进程默认由 root 启动。

HUP 信号对 Tor 守护进程的确切作用记录在: https://gitweb.torproject.org/torspec.git/tree/control-spec.txt?id=03aaace9bd9459b0d4bf22a75012acf39d07bcec#n394 相当于通过命令端口发送一些命令。

Browser Bundle 5.0.5 不受此影响,只有守护进程端口(例如默认 9050),TBB 不使用该端口。对于该用例,请参阅:https:// tor.stackexchange.com/questions/1071/how-can-a-new-circle-happen-without-looking-all-tabs

如果您正在部署大量 Tor IP 正如这里提到的,您可以有选择地发送:

kill -HUP $PID

我们可以按端口选择 PID,如下所示:https://unix.stackexchange.com/questions/106561/finding-the-pid-of-the-process- using-a-specific-port 例如更改在端口 9050 侦听的 Tor 的 IP:

kill -HUP "$(sudo netstat -nlp | awk '$4~":9050"{ gsub(/\/.*/,"",$7); print $7 }')"

方法 2:控制端口

kat

(echo authenticate '""'; echo signal newnym; echo quit) | nc localhost 9051

但要在 Ubuntu 17.10 上运行,您必须首先

  • 通过取消注释来启用控制端口:

    <前><代码>控制端口 9051

    来自/etc/tor/torrc

  • 设置空密码,否则会给出 515 身份验证失败:身份验证 cookie 长度错误。。第一次运行:

    tor --hash-password ''
    

    输出如下:

    <前><代码>16:D14CC89AD7848B8C60093105E8284A2D3AB2CF3C20D95FECA0848CFAD2

    现在在 /etc/tor/torrc 上更新行:

    <前><代码>HashedControlPassword 16:D14CC89AD7848B8C60093105E8284A2D3AB2CF3C20D95FECA0848CFAD2

  • 重新启动 Tor:

    sudo 服务重启
    

相关主题

Method 1: HUP

sudo killall -HUP tor

Then check that your IP has changed with:

curl --socks5 127.0.0.1:9050 http://checkip.amazonaws.com/

Tested in Ubuntu 17.10 with sudo apt-get install tor version 1.6.0-5.

sudo is needed since the process is started by root by default.

What an HUP signal does exactly to the Tor daemon is documented at: https://gitweb.torproject.org/torspec.git/tree/control-spec.txt?id=03aaace9bd9459b0d4bf22a75012acf39d07bcec#n394 and is equivalent to sending some command through the command port.

Browser Bundle 5.0.5 is not affected by this, only daemon ports like the default 9050, which is not used by the TBB. For that use case see: https://tor.stackexchange.com/questions/1071/how-can-a-new-circuit-happen-without-closing-all-tabs

If you are deploying an army of Tor IPs as mentioned here you can selectively send:

kill -HUP $PID

We can select the PID by port as per: https://unix.stackexchange.com/questions/106561/finding-the-pid-of-the-process-using-a-specific-port E.g. to change IP of the Tor listening in at port 9050:

kill -HUP "$(sudo netstat -nlp | awk '$4~":9050"{ gsub(/\/.*/,"",$7); print $7 }')"

Method 2: control port

Mentioned by kat:

(echo authenticate '""'; echo signal newnym; echo quit) | nc localhost 9051

but for that to work on Ubuntu 17.10 you must first:

  • enable the control port by uncommenting:

    ControlPort 9051
    

    from /etc/tor/torrc

  • Set the empty password, otherwise it gives 515 Authentication failed: Wrong length on authentication cookie.. First run:

    tor --hash-password ''
    

    This outputs something like:

    16:D14CC89AD7848B8C60093105E8284A2D3AB2CF3C20D95FECA0848CFAD2
    

    Now on /etc/tor/torrc update the line:

    HashedControlPassword 16:D14CC89AD7848B8C60093105E8284A2D3AB2CF3C20D95FECA0848CFAD2
    
  • Restart Tor:

    sudo service tor restart
    

Related threads

隔岸观火 2024-08-23 08:48:32
(echo authenticate '""'; echo signal newnym; echo quit) | nc localhost 9051
(echo authenticate '""'; echo signal newnym; echo quit) | nc localhost 9051
原谅过去的我 2024-08-23 08:48:32

这个问题似乎经常出现(1,2),所以我刚刚添加了 常见问题解答条目 。如前所述,您可以通过 NEWNYM 信号来完成此操作。这是通过 stem 执行此操作的示例...

from stem import Signal
from stem.control import Controller

with Controller.from_port(port = 9051) as controller:
  controller.authenticate()
  controller.signal(Signal.NEWNYM)

This question seems to come up pretty frequently (1, 2) so I just added a FAQ entry for it. As mentioned earlier you can do this via a NEWNYM signal. Here's an example for doing it via stem...

from stem import Signal
from stem.control import Controller

with Controller.from_port(port = 9051) as controller:
  controller.authenticate()
  controller.signal(Signal.NEWNYM)
瑾兮 2024-08-23 08:48:32

是的,那就是 1(我的意思是 =true =)))tor 每 10 分钟就会更改一次 ip
但!如果我重新启动tor - 即使在这10分钟的间隔内我也会得到一个新的IP。
所以我正在考虑让tor手动发送这个“change_ip”请求。
请参阅此代码(根据 http://en.linuxreviews.org/HOWTO_use_the_Internet_anonymously_using_Tor_and_Privoxy 编写)

procedure ChangeIp;
var
  sck:TIdTCPClient;
begin
  sck:=TIdTCPClient.Create(nil);
  try
    sck.Host:='127.0.0.1';
    sck.Port:=10051;
    sck.Connect;
    sck.SendCmd('authenticate','');
    if sck.LastCmdResult.Code='250' then
    begin
      sck.SendCmd('signal newnym','');
    end;
  finally
    sck.Free;
  end;
end;

并按照 [ https://tor-svn.freehaven.net/svn/ torctl/trunk/doc/howto.txt] 我可以编写一个控制器来动态更改 Tor 的配置。
默认情况下它没有启用(我的意思是这种能力),但我可以让tor客户端监听某个端口以使用torrc接受命令...如果我没有记错的话...再次=)

!!! torrc 在我的电脑上到底在哪里?

在 C:\Users\geekman\AppData\Roaming\Tor 我可以找到它
我有远景。

yeah, that's 1 (i mean =true =))) that tor does change ip every 10 minutes
but! if i restart tor - i'll get a new ip even in this 10minutes interval.
so i was thinking about making tor to send this "change_ip" request manually.
see this code (written according to http://en.linuxreviews.org/HOWTO_use_the_Internet_anonymously_using_Tor_and_Privoxy)

procedure ChangeIp;
var
  sck:TIdTCPClient;
begin
  sck:=TIdTCPClient.Create(nil);
  try
    sck.Host:='127.0.0.1';
    sck.Port:=10051;
    sck.Connect;
    sck.SendCmd('authenticate','');
    if sck.LastCmdResult.Code='250' then
    begin
      sck.SendCmd('signal newnym','');
    end;
  finally
    sck.Free;
  end;
end;

and accornig to [https://tor-svn.freehaven.net/svn/torctl/trunk/doc/howto.txt] i can write a controler that will change tor's conf on the fly.
by default it is not enebled (i mean this ability), but i can make tor client listen to some port for accepting commands using torrc...if i'm not mistaken...again=)

!!! where the hell torrc is on my pc?

In C:\Users\geekman\AppData\Roaming\Tor i could,n fing it
i got vista.

赠我空喜 2024-08-23 08:48:32

我为自己制作了一个 shell 脚本,也可以让您远程执行此操作(如果 Tor 服务器在另一台机器上运行)。

它可以在这里找到:https://gist.github.com/kirelagin/9667900

I've made a shell script for myself that also lets you do this remotely (if Tor server is running on another machine).

It's available here: https://gist.github.com/kirelagin/9667900.

海风掠过北极光 2024-08-23 08:48:32

您只需在 bash 脚本中输入或插入:

service tor reload

You can simply type or insert in your bash script:

service tor reload
何以心动 2024-08-23 08:48:32

如果您无权访问控制端口,您可以使用不同的电路来更改您的 IP*。这可以通过指定不同的socks用户名来完成:

$ curl -x "socks5://[email protected]:9050" "https://ifconfig.io/ip"
109.70.100.34

$ curl -x "socks5://[email protected]:9050" "https://ifconfig.io/ip"
209.222.101.251

$ curl -x "socks5://[email protected]:9050" "https://ifconfig.io/ip"
54.37.19.83

如果您想在某个时候重复使用特定的IP,您可以使用之前使用的相同用户名再次获取该IP。

* 每次退出节点都是随机的,并且有轻微的机会你会连续两次获得相同的IP。

如果我错了,请纠正我,我不是 Tor 专家,但这对我有用。

If you don't have access to the control port, you could use a different circuit which changes your IP*. This can be done by specifying a different socks username:

$ curl -x "socks5://[email protected]:9050" "https://ifconfig.io/ip"
109.70.100.34

$ curl -x "socks5://[email protected]:9050" "https://ifconfig.io/ip"
209.222.101.251

$ curl -x "socks5://[email protected]:9050" "https://ifconfig.io/ip"
54.37.19.83

If you want to reuse a specific IP at some point you can use the same username you used before to get that IP again.

* The exit node will be random every time and there is a slight chance you'll get the same IP twice in a row.

Correct me if I'm wrong, I'm not a Tor expert, but this works for me.

奈何桥上唱咆哮 2024-08-23 08:48:32

您无法控制 Tor 网络中的路由(如果有的话,有人可能会滥用此功能)。但 Tor 已经大约每 10 分钟切换一次路线(至少根据德语维基百科文章< /a>)。

You have no control over the routing in the tor network (if you had, someone could abuse this feature). But tor already switches the route roughly every 10 minutes (at least according to the German Wikipedia article).

千里故人稀 2024-08-23 08:48:32

Advtor 使您可以访问几乎所有通过 Tor 网络运行的高级设置。

Advtor gives you access over almost all advanced settings which works over tor network.

南城追梦 2024-08-23 08:48:32

我在这里做了一些不同的事情...我编写了一个可以与 linux shell 通信的 PHP 程序。该程序将定期重新启动 tor。

所以当tor重新启动时,它会获得一个新的IP....是的......!!

exec("/etc/init.d/tor restart",$ioOut);
print_r($ioOut); //output from shell after executing the command
sleep(25);

您还可以编写 shell 脚本来执行此操作。

我现在正在寻找一个 Windows 选项来执行此操作。问题是..在Windows中Tor是一个无法重新启动的服务。

I have done something different here... i wrote a PHP program that can communicate with linux shell. The program would restart tor in regular intervals.

So when tor is restarted it gets a new IP.... Yeah.....!!

exec("/etc/init.d/tor restart",$ioOut);
print_r($ioOut); //output from shell after executing the command
sleep(25);

You can also write a shell script to do this.

I am now in search of a windows option to do this. The problem is .. in windows Tor is a service which cannot be restarted.

话少情深 2024-08-23 08:48:32

我编写了一个库来使用 PHP 控制 Tor。它可以与 Composer 一起安装,并允许更改退出节点。

当然它是免费软件:http://dunglas。 fr/2013/02/php-torcontrol-a-library-to-control-tor/

I've wrote a library to control Tor with PHP. It is installable with Composer and allows to change the exit node.

Of course it's free software: http://dunglas.fr/2013/02/php-torcontrol-a-library-to-control-tor/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文