For some needs I'd like a python app to connect to a tor proxy but instead of the DNS I want to use the static ip. Indeed when I
I'm unable to make it happen. The request is always timed out when I want to connect to the database.
Here is my docker-compose file :
version: "3.9"
services:
test:
image: busybox
command: ifconfig
networks:
app_net:
ipv4_address: 172.18.18.9
app:
build: ./python
depends_on:
- tor
tor:
build:
context: ./tor
container_name: tor
environment:
- TOR_INSTANCES=1
- TOR_HASHED_PASSWORD=16:D87F66F5B5E2A6BC605544DBB4720DAD433C1E8CE7D18F835D58A4353E
- TOR_PROXIES_CONTROLLER_AUTH_PASSWORD=testtor
- TOR_CONTROLLER_HOST=172.18.18.10
ports:
- "9050-9060:9050-9060"
- "10000-10050:10000-10050"
networks:
app_net:
ipv4_address: 172.18.18.10
networks:
app_net:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.18.18.0/24
gateway: 172.18.18.1
My python code is very simple, this is what i'm trying to do :
- Get IP from requests (without proxies)
- Same but with proxy
- Renew proxy
- Perform requests again
The first request passes well but then it timeouts with the proxies. Obvisously I can't renew the IP either as the ip so not resolved.
^[[Dapp_1 | After request :: https://ifconfig.io/ip 200 82.123.30.131
app_1 |
app_1 | SOCKSHTTPSConnectionPool(host='ifconfig.io', port=443): Max retries exceeded with url: /ip (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0xffffbcb16940>: Failed to establish a new connection: [Errno -2] Name or service not known'))
app_1 | Traceback (most recent call last):
app_1 | File "/usr/local/lib/python3.8/site-packages/stem/socket.py", line 535, in _make_socket
app_1 | control_socket.connect((self.address, self.port))
app_1 | TimeoutError: [Errno 110] Connection timed out
However if I only execute the tor docker-container, and I replace the tor proxy by "localhost", it works totally fine :
def add_proxies(self):
self.http.proxies['http'] = 'socks5://localhost:9051'
self.http.proxies['https'] = 'socks5://localhost:9051'
def renew_proxy_ip(self):
with Controller.from_port(port=10001) as controller:
controller.authenticate(password="testtor")
print("Authentication :: ", controller.is_authenticated())
controller.signal(Signal.NEWNYM)
Output is expected
After request :: https://ifconfig.io/ip 200 2a01:cb04:be0:b300:d44d:f8d3:6328:b2f1
After request :: https://ifconfig.io/ip 200 2a00:1768:6001:28:2236::1
Authentication :: True
After request :: https://ifconfig.io/ip 200 2a03:4000:37:645::
I added a ifconfig busybox to see if ip is correctly mapped, which is the case :
test_1 | eth0 Link encap:Ethernet HWaddr 02:42:AC:12:12:09
test_1 | inet addr:172.18.18.9 Bcast:172.18.18.255 Mask:255.255.255.0
test_1 | UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
test_1 | RX packets:2 errors:0 dropped:0 overruns:0 frame:0
test_1 | TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
test_1 | collisions:0 txqueuelen:0
test_1 | RX bytes:200 (200.0 B) TX bytes:0 (0.0 B)
test_1 |
test_1 | lo Link encap:Local Loopback
test_1 | inet addr:127.0.0.1 Mask:255.0.0.0
test_1 | UP LOOPBACK RUNNING MTU:65536 Metric:1
test_1 | RX packets:0 errors:0 dropped:0 overruns:0 frame:0
test_1 | TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
test_1 | collisions:0 txqueuelen:1000
test_1 | RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
I created a repo where you can reproduce the issue : https://github.com/thibault-lr/docker-static-ip simply with a docker-compose up
I'm a bit obliged to proceed so, the controller authication requires an IP to connect to. I've been stuck to this for a while, I'd like to know if someone experienced this issue already ? I'm on macos and tried on a linux server it remains the same
There are other solutions that I didn't explore if this is not possible :
- Use the telnet to connect to tor network using a DNS
- Auth with socket files
Huge thanks in advance ! TL