TorGo连接到在Docker Compose中运行的Tor ControlPort

huangapple go评论74阅读模式
英文:

TorGo Connect to Tor ControlPort Running In Docker Compose

问题

我有一个docker-compose文件,其中运行了一个Tor节点,我还有一个简单的Go脚本,试图使用torgo连接到该Tor节点。

我运行docker-compose,然后运行一个简单的curl命令来检查SOCKS5代理是否正常工作,一切都正常:

$ curl --socks5 127.0.0.1:9050 https://check.torproject.org/api/ip
{"IsTor":true,"IP":"185.83.214.69"}

但是,如果我运行我的Go脚本尝试使用端口9051连接以获取控制器实例,每次尝试都会失败并显示错误EOF

我还尝试通过telnet连接,也收到错误信息:

$ telnet 127.0.0.1 9051
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host.

到目前为止,我尝试了许多不同的方法,现在无法一一列举,但包括使用不同的docker镜像,挂载自己的带有启用身份验证和其他参数的torrc配置文件等等。没有任何方法有效...

我漏掉了什么?如何连接到ControlPort

docker-compose

version: "3.8"

services:
  torproxy:
    restart: always
    image: dperson/torproxy:latest
    ports:
      - "9050:9050" # Tor proxy
      - "9051:9051" # Tor control port
      - "8118:8118" # Privoxy

main.go

package main

import (
	"github.com/wybiral/torgo"
	"log"
)

func main() {
	addr := "127.0.0.1:9051"
	c, err := torgo.NewController(addr)
	if err != nil {
		log.Fatalf("failed to create tor controller: %s", err)
	}
	log.Println(c)
}
英文:

I have a docker-compose file which runs a tor node and I also have a simple Go script which attempts to use torgo to connect to said tor node.

I run the docker-compose and then I run a simple curl command to check that the SOCKS5 proxy is working, all is fine:

$ curl --socks5 127.0.0.1:9050 https://check.torproject.org/api/ip
{"IsTor":true,"IP":"185.83.214.69"}

But if I run my Go script to try and connect with port 9051 to get a controller instance, every attempt fails with error EOF.

I've also tried connecting via telnet and receive errors there as well:

$ telnet 127.0.0.1 9051
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host.

I've tried a number of different things at this point, too many to recall right now but things including, different docker images, mounting my own torrc config with auth enabled and various other parameters, etc. Nothing is working...

What am I missing? How can I connect to the ControlPort?

docker-compose

version: "3.8"

services:
  torproxy:
    restart: always
    image: dperson/torproxy:latest
    ports:
      - "9050:9050" # Tor proxy
      - "9051:9051" # Tor control port
      - "8118:8118" # Privoxy

main.go

package main

import (
	"github.com/wybiral/torgo"
	"log"
)

func main() {
	addr := "127.0.0.1:9051"
	c, err := torgo.NewController(addr)
	if err != nil {
		log.Fatalf("failed to create tor controller: %s", err)
	}
	log.Println(c)
}

答案1

得分: 1

我终于成功通过在torrc中将ControlPort绑定到0.0.0.0:9051,而不是默认值,来连接到Docker tor实例。

torrc默认配置

ControlPort 9051

更新后的torrc配置

ControlPort 0.0.0.0:9051

这样可以使控制端口从容器外部访问。

这个Stack Overflow的帖子帮助我找到了这个答案:
https://stackoverflow.com/a/58138489/5750392

英文:

I was finally able to connect to the Docker tor instance by binding the ControlPort to 0.0.0.0:9051 in torrc, rather than the default.

torrc default

ControlPort 9051

torrc updated

ControlPort 0.0.0.0:9051

This makes the control port accessible from outside the container.

This SO post got me to this answer:
https://stackoverflow.com/a/58138489/5750392

huangapple
  • 本文由 发表于 2021年10月10日 09:20:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/69511614.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定