Reputation: 571
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?
Upvotes: 1
Views: 2147
Reputation: 51
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
`
Upvotes: 2