1

I've been trying to find out how I would connect to a TOR proxy or connect to the TOR network. With the Socksipy module, I see that people (other stack overflow TOR python questions) can connect to a proxy, but I do not understand a concept.

import socks, socket
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 9050) #localhost??
socket.socket = socks.socksocket

I do get how you can connect to a TOR proxy, but the proxy is your local host just through port 9050? Is this because everyone does not want to show real TOR proxy? How do I connect to a TOR proxy, and if this is the case, why?

1
  • you may try to cat the torsocks.conf to read more info about why 127.0.0.1 was set default. or take a look at this Commented Oct 13, 2014 at 10:54

1 Answer 1

2

try this, before request

`

import socks
import socket
SOCKS_PORT = 9050  # TOR proxy port that is default from torrc, change to whatever torrc is configured to

socks.set_default_proxy(socks.SOCKS5, "127.0.0.1",SOCKS_PORT)
socket.socket = socks.socksocket

# Perform DNS resolution through the socket
def getaddrinfo(*args):
  return [(socket.AF_INET, socket.SOCK_STREAM, 6, '', (args[0], args[1]))]
socket.getaddrinfo = getaddrinfo

`

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.