Last active
March 23, 2019 16:56
-
-
Save AnyKeyShik/5ba268d59411b5ea36b8c125b8db995a to your computer and use it in GitHub Desktop.
Simple proxy tor config with PySocks lib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import socket, socks | |
def create_connection(address): | |
""" | |
Create connection with custom sock | |
:param address: address for connection | |
:return: connection sock | |
:rtype: socks.socksocket | |
""" | |
sock = socks.socksocket() | |
sock.connect(address) | |
return sock | |
def config(ip, port): | |
""" | |
Config proxy | |
:param ip: proxy ip | |
:param port: proxy port | |
:return: None | |
:rtype: None | |
""" | |
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, ip, port) | |
def patch(): | |
""" | |
Patch the socket module | |
:return: None | |
:rtype: None | |
""" | |
config("127.0.0.1", 9050) | |
socket.socket = socks.socksocket | |
socket.create_connection = create_connection |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment