To send a Tor request to a URL in Python with PySocks, you can use the following example code that supports IPv6:

import socks
import socket
import requests

# Set up the Tor proxy
socks.set_default_proxy(socks.SOCKS5, "localhost", 9050, True, None, None)

# Set the socket to use IPv6
socks.socket = socks.socksocket
socks.socket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)

# Make the request through Tor
response = requests.get("https://example.com")

# Print the response
print(response.content)

In this code, we first set up the Tor proxy with socks.set_default_proxy. We use SOCKS5, set the proxy address to localhost and port to 9050, and set True for the rdns parameter to resolve DNS requests through Tor.

Next, we set the socks.socket to use IPv6 by setting it to socks.socksocket and then calling setsockopt with socket.IPPROTO_IPV6 and socket.IPV6_V6ONLY set to 0.

Finally, we make the request using requests.get and print the response. This code should work with PySocks versions that support IPv6

how to send tor request to url in python with example code PySocks to a version that supports IPv6

原文地址: https://www.cveoy.top/t/topic/dUle 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录