简体   繁体   中英

Python - How to connect to TOR proxy

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?

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

`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM