PySocks lets you send traffic through SOCKS proxy servers.

Overview

PySocks

PySocks lets you send traffic through SOCKS proxy servers. It is a modern fork of SocksiPy with bug fixes and extra features.

Acts as a drop-in replacement to the socket module. Seamlessly configure SOCKS proxies for any socket object by calling socket_object.set_proxy().


Features

  • SOCKS proxy client for Python 2.7 and 3.4+
  • TCP supported, UDP mostly supported (issues may occur in some edge cases)
  • HTTP proxy client included but not supported or recommended (you should use requests', or your HTTP client's, own HTTP proxy interface)
  • urllib2 handler included, but not supported. pip install / setup.py install will automatically install the sockshandler module.

Installation

pip install pysocks

Or download the tarball / git clone and...

python setup.py install

These will install both the socks and sockshandler modules.

Alternatively, include just socks.py in your project.

Proxying HTTP Traffic

We highly recommend using the requests library for proxying HTTP traffic with SOCKS or HTTP proxies. It uses PySocks under the hood.

requests.get(url, proxies={"http": "socks5://proxyhostname:9050", "https": "socks5://proxyhostname:9050"})

PySocks has an option for HTTP proxies, but it only supports CONNECT-based HTTP proxies, and in general we recommend using your HTTP client's native proxy support (such as requests' proxies keyword argument) rather than PySocks'.

If you absolutely must, you can use the urllib2 handler in sockshandler.py, but it's not supported (and won't work for non-CONNECT-based HTTP proxies, as stated above).


Usage

socks.socksocket

import socks

s = socks.socksocket() # Same API as socket.socket in the standard lib

s.set_proxy(socks.SOCKS5, "localhost") # SOCKS4 and SOCKS5 use port 1080 by default
# Or
s.set_proxy(socks.SOCKS4, "localhost", 4444)
# Or
s.set_proxy(socks.HTTP, "5.5.5.5", 8888)

# Can be treated like a regular socket object
s.connect(("www.somesite.com", 80))
s.sendall("GET / HTTP/1.1 ...")
print(s.recv(4096))

Monkeypatching

To monkeypatch the entire standard library with a single default proxy:

import urllib2
import socket
import socks

socks.set_default_proxy(socks.SOCKS5, "localhost")
socket.socket = socks.socksocket

Note that monkeypatching may not work for all standard modules or for all third party modules, and generally isn't recommended. Monkeypatching is usually an anti-pattern in Python.


Original SocksiPy README attached below, amended to reflect API changes.


SocksiPy

A Python SOCKS module.

(C) 2006 Dan-Haim. All rights reserved.

See LICENSE file for details.

WHAT IS A SOCKS PROXY?

A SOCKS proxy is a proxy server at the TCP level. In other words, it acts as a tunnel, relaying all traffic going through it without modifying it. SOCKS proxies can be used to relay traffic using any network protocol that uses TCP.

WHAT IS SOCKSIPY?

This Python module allows you to create TCP connections through a SOCKS proxy without any special effort. It also supports relaying UDP packets with a SOCKS5 proxy.

PROXY COMPATIBILITY

SocksiPy is compatible with three different types of proxies:

  1. SOCKS Version 4 (SOCKS4), including the SOCKS4a extension.
  2. SOCKS Version 5 (SOCKS5).
  3. HTTP Proxies which support tunneling using the CONNECT method.

SYSTEM REQUIREMENTS

Being written in Python, SocksiPy can run on any platform that has a Python interpreter and TCP/IP support. This module has been tested with Python 2.3 and should work with greater versions just as well.

INSTALLATION

Simply copy the file "socks.py" to your Python's lib/site-packages directory, and you're ready to go. [Editor's note: it is better to use python setup.py install for PySocks]

USAGE

First load the socks module with the command:

>>> import socks
>>>

The socks module provides a class called socksocket, which is the base to all of the module's functionality.

The socksocket object has the same initialization parameters as the normal socket object to ensure maximal compatibility, however it should be noted that socksocket will only function with family being AF_INET and type being either SOCK_STREAM or SOCK_DGRAM. Generally, it is best to initialize the socksocket object with no parameters

>>> s = socks.socksocket()
>>>

The socksocket object has an interface which is very similiar to socket's (in fact the socksocket class is derived from socket) with a few extra methods. To select the proxy server you would like to use, use the set_proxy method, whose syntax is:

set_proxy(proxy_type, addr[, port[, rdns[, username[, password]]]])

Explanation of the parameters:

proxy_type - The type of the proxy server. This can be one of three possible choices: PROXY_TYPE_SOCKS4, PROXY_TYPE_SOCKS5 and PROXY_TYPE_HTTP for SOCKS4, SOCKS5 and HTTP servers respectively. SOCKS4, SOCKS5, and HTTP are all aliases, respectively.

addr - The IP address or DNS name of the proxy server.

port - The port of the proxy server. Defaults to 1080 for socks and 8080 for http.

rdns - This is a boolean flag than modifies the behavior regarding DNS resolving. If it is set to True, DNS resolving will be preformed remotely, on the server. If it is set to False, DNS resolving will be preformed locally. Please note that setting this to True with SOCKS4 servers actually use an extension to the protocol, called SOCKS4a, which may not be supported on all servers (SOCKS5 and http servers always support DNS). The default is True.

username - For SOCKS5 servers, this allows simple username / password authentication with the server. For SOCKS4 servers, this parameter will be sent as the userid. This parameter is ignored if an HTTP server is being used. If it is not provided, authentication will not be used (servers may accept unauthenticated requests).

password - This parameter is valid only for SOCKS5 servers and specifies the respective password for the username provided.

Example of usage:

>> s.set_proxy(socks.SOCKS4, "socks.test.com", 1081) ">
>>> s.set_proxy(socks.SOCKS5, "socks.example.com") # uses default port 1080
>>> s.set_proxy(socks.SOCKS4, "socks.test.com", 1081)

After the set_proxy method has been called, simply call the connect method with the traditional parameters to establish a connection through the proxy:

>> ">
>>> s.connect(("www.sourceforge.net", 80))
>>>

Connection will take a bit longer to allow negotiation with the proxy server. Please note that calling connect without calling set_proxy earlier will connect without a proxy (just like a regular socket).

Errors: Any errors in the connection process will trigger exceptions. The exception may either be generated by the underlying socket layer or may be custom module exceptions, whose details follow:

class ProxyError - This is a base exception class. It is not raised directly but rather all other exception classes raised by this module are derived from it. This allows an easy way to catch all proxy-related errors. It descends from IOError.

All ProxyError exceptions have an attribute socket_err, which will contain either a caught socket.error exception, or None if there wasn't any.

class GeneralProxyError - When thrown, it indicates a problem which does not fall into another category.

  • Sent invalid data - This error means that unexpected data has been received from the server. The most common reason is that the server specified as the proxy is not really a SOCKS4/SOCKS5/HTTP proxy, or maybe the proxy type specified is wrong.

  • Connection closed unexpectedly - The proxy server unexpectedly closed the connection. This may indicate that the proxy server is experiencing network or software problems.

  • Bad proxy type - This will be raised if the type of the proxy supplied to the set_proxy function was not one of SOCKS4/SOCKS5/HTTP.

  • Bad input - This will be raised if the connect() method is called with bad input parameters.

class SOCKS5AuthError - This indicates that the connection through a SOCKS5 server failed due to an authentication problem.

  • Authentication is required - This will happen if you use a SOCKS5 server which requires authentication without providing a username / password at all.

  • All offered authentication methods were rejected - This will happen if the proxy requires a special authentication method which is not supported by this module.

  • Unknown username or invalid password - Self descriptive.

class SOCKS5Error - This will be raised for SOCKS5 errors which are not related to authentication. The parameter is a tuple containing a code, as given by the server, and a description of the error. The possible errors, according to the RFC, are:

  • 0x01 - General SOCKS server failure - If for any reason the proxy server is unable to fulfill your request (internal server error).
  • 0x02 - connection not allowed by ruleset - If the address you're trying to connect to is blacklisted on the server or requires authentication.
  • 0x03 - Network unreachable - The target could not be contacted. A router on the network had replied with a destination net unreachable error.
  • 0x04 - Host unreachable - The target could not be contacted. A router on the network had replied with a destination host unreachable error.
  • 0x05 - Connection refused - The target server has actively refused the connection (the requested port is closed).
  • 0x06 - TTL expired - The TTL value of the SYN packet from the proxy to the target server has expired. This usually means that there are network problems causing the packet to be caught in a router-to-router "ping-pong".
  • 0x07 - Command not supported - For instance if the server does not support UDP.
  • 0x08 - Address type not supported - The client has provided an invalid address type. When using this module, this error should not occur.

class SOCKS4Error - This will be raised for SOCKS4 errors. The parameter is a tuple containing a code and a description of the error, as given by the server. The possible error, according to the specification are:

  • 0x5B - Request rejected or failed - Will be raised in the event of an failure for any reason other then the two mentioned next.
  • 0x5C - request rejected because SOCKS server cannot connect to identd on the client - The Socks server had tried an ident lookup on your computer and has failed. In this case you should run an identd server and/or configure your firewall to allow incoming connections to local port 113 from the remote server.
  • 0x5D - request rejected because the client program and identd report different user-ids - The Socks server had performed an ident lookup on your computer and has received a different userid than the one you have provided. Change your userid (through the username parameter of the set_proxy method) to match and try again.

class HTTPError - This will be raised for HTTP errors. The message will contain the HTTP status code and provided error message.

After establishing the connection, the object behaves like a standard socket.

Methods like makefile() and settimeout() should behave just like regular sockets. Call the close() method to close the connection.

In addition to the socksocket class, an additional function worth mentioning is the set_default_proxy function. The parameters are the same as the set_proxy method. This function will set default proxy settings for newly created socksocket objects, in which the proxy settings haven't been changed via the set_proxy method. This is quite useful if you wish to force 3rd party modules to use a SOCKS proxy, by overriding the socket object. For example:

>> socket.socket = socks.socksocket >>> urllib.urlopen("http://www.sourceforge.net/") ">
>>> socks.set_default_proxy(socks.SOCKS5, "socks.example.com")
>>> socket.socket = socks.socksocket
>>> urllib.urlopen("http://www.sourceforge.net/")

PROBLEMS

Please open a GitHub issue at https://github.com/Anorov/PySocks

Comments
  • DeprecationWarning in socks.py

    DeprecationWarning in socks.py "Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working"

    Environment

    • pytest 4.0.0
    • Python 3.7.1
    • Annaconda
    • Windows10
    > pytest --version
    This is pytest version 4.0.0, imported from c:\programdata\anaconda3\lib\site-packages\pytest.py
    setuptools registered plugins:
      pytest-remotedata-0.3.0 at c:\programdata\anaconda3\lib\site-packages\pytest_remotedata\plugin.py
      pytest-openfiles-0.3.0 at c:\programdata\anaconda3\lib\site-packages\pytest_openfiles\plugin.py
      pytest-doctestplus-0.1.3 at c:\programdata\anaconda3\lib\site-packages\pytest_doctestplus\plugin.py
      pytest-arraydiff-0.2 at c:\programdata\anaconda3\lib\site-packages\pytest_arraydiff\plugin.py
    

    Warning

    DeprecationWarning causes in socks.py when pytest command is executed.

    https://github.com/pytest-dev/pytest/issues/4769

    > pytest tests/
    ============================= test session starts =============================
    platform win32 -- Python 3.7.1, pytest-4.0.0, py-1.6.0, pluggy-0.7.1 -- c:\programdata\anaconda3\python.exe
    cachedir: .pytest_cache
    rootdir: C:\vagrant\synced_folder\annofab-api-access-python-commons, inifile: pytest.ini
    plugins: remotedata-0.3.0, openfiles-0.3.0, doctestplus-0.1.3, arraydiff-0.2
    collected 1 items
    
    tests/test_annofab.py::test_account PASSED
    
    ============================== warnings summary ===============================
    c:\programdata\anaconda3\lib\site-packages\socks.py:58
      c:\programdata\anaconda3\lib\site-packages\socks.py:58: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
        from collections import Callable
    
    opened by yuji38kwmt 7
  • SOCKS5 and UDP error

    SOCKS5 and UDP error

    I'm trying to write a small test application to test if a Proxy supports UDP over SOCKS5.

    Currently the application seems to be sending messages correctly but receiving is falling over when receiving the echoed data. File "E:\pacs\socks.py", line 330, in recvfrom peerhost, peerport = self.proxy_peername TypeError: 'NoneType' object is not iterable

    I cannot see how self.proxy_peername is being initialized with socks5 proxy. My test environment is using proxy plus (free edition) with SOCKS activated and the following code

    #! /usr/bin/env python
    
    # Client and server for udp (datagram) echo.
    #
    # Usage: udpecho -s [port]            (to start a server)
    # or:    udpecho -c host [port] <file (client)
    
    import sys
    import socks
    from socket import *
    
    ECHO_PORT = 50000 + 7
    BUFSIZE = 1024
    
    def main():
        if len(sys.argv) < 2:
            usage()
        if sys.argv[1] == '-s':
            server()
        elif sys.argv[1] == '-c':
            client()
        elif sys.argv[1] == '-ss':
            sockserver()
        elif sys.argv[1] == '-sc':
            sockclient()
        else:
            usage()
    
    def usage():
        sys.stdout = sys.stderr
        print 'Usage: udpecho -s [port]            (server)'
        print 'or:    udpecho -c host [port] <file (client)'
        sys.exit(2)
    
    def server():
        if len(sys.argv) > 2:
            port = eval(sys.argv[2])
        else:
            port = ECHO_PORT
        s = socket(AF_INET, SOCK_DGRAM)
        s.bind(('', port))
        print 'udp echo server ready'
        while 1:
            data, addr = s.recvfrom(BUFSIZE)
            print 'server received', `data`, 'from', `addr`
            s.sendto(data, addr)
    
    def client():
        if len(sys.argv) < 3:
            usage()
        host = sys.argv[2]
        if len(sys.argv) > 3:
            port = eval(sys.argv[3])
        else:
            port = ECHO_PORT
        addr = host, port
        s = socket(AF_INET, SOCK_DGRAM)
        s.settimeout(100)
        s.bind(('', 0))
        print 'udp echo client ready, reading stdin'
        while 1:
            line = sys.stdin.readline()
            if not line:
                break
            s.sendto(line, addr)
            data, fromaddr = s.recvfrom(BUFSIZE)
            print 'client received', `data`, 'from', `fromaddr`
    
    def sockserver():
        if len(sys.argv) > 2:
            port = eval(sys.argv[2])
        else:
            port = ECHO_PORT
        socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 1080)
        s = socks.socksocket(AF_INET, SOCK_DGRAM)
        s.bind(('', port))
        print 'udp echo server ready'
        while 1:
            data, addr = s.recvfrom(BUFSIZE)
            print 'server received', `data`, 'from', `addr`
            s.sendto(data, addr)
    
    def sockclient():
        if len(sys.argv) < 3:
            usage()
        host = sys.argv[2]
        if len(sys.argv) > 3:
            port = eval(sys.argv[3])
        else:
            port = ECHO_PORT
        addr = host, port
        s = socks.socksocket(AF_INET, SOCK_DGRAM)
        s.set_proxy(socks.SOCKS5, "localhost")
        s.settimeout(100)
        s.bind(('', 0))
    
        print 'udp echo client ready, reading stdin'
        try:
            while 1:
                line = sys.stdin.readline()
                if not line:
                    break
                print 'sending', line, 'to', addr
                s.sendto(line, addr)
                res = s.recvfrom(BUFSIZE)
                print '%r' % res
                print 'client received', `data`, 'from', `fromaddr`
        except KeyboardInterrupt:
            print 'Bye'
            pass
    
    main()
    

    In one command window I run: udpecho.py -s

    In the another window: udpecho.py -sc localhost test

    The send is working as the server sees udp echo server ready server received 'test\n' from ('127.0.0.1', 49165)

    But the receive is failing.

    opened by duncanwebb 7
  • urllib2 timeout and gevent 1.0

    urllib2 timeout and gevent 1.0

    when using urllib2 + gevent 1.0 and setting timeout on request i got error "send() got an unexpected keyword argument 'timeout'

    backtrace [...
     ('/usr/lib64/python2.7/urllib2.py', 400, 'open', 'response = self._open(req, data)'), ('/usr/lib64/python2.7/urllib2.py', 418, '_open', "'_open', req)"), ('/usr/lib64/python2.7/urllib2.py', 378, '_call_chain', 'result = func(*args)'), ('./main/sockshandler.py', 49, 'http_open', 'return self.do_open(build, req)'), ('/usr/lib64/python2.7/urllib2.py', 1174, 'do_open', 'h.request(req.get_method(), req.get_selector(), req.data, headers)'), ('/usr/lib64/python2.7/httplib.py', 958, 'request', 'self._send_request(method, url, body, headers)'), ('/usr/lib64/python2.7/httplib.py', 992, '_send_request', 'self.endheaders(body)'), ('/usr/lib64/python2.7/httplib.py', 954, 'endheaders', 'self._send_output(message_body)'), ('/usr/lib64/python2.7/httplib.py', 814, '_send_output', 'self.send(msg)'), ('/usr/lib64/python2.7/httplib.py', 776, 'send', 'self.connect()'), 
    ('./main/sockshandler.py', 24, 'connect', 'self.sock.connect((self.host, self.port))'), ('.../v/lib/python2.7/site-packages/socks.py', 668, 'connect', 'negotiate(self, dest_addr, dest_port)'), ('.../v/lib/python2.7/site-packages/socks.py', 378, '_negotiate_SOCKS5', 'CONNECT, dest_addr)'), ('.../v/lib/python2.7/site-packages/socks.py', 460, '_SOCKS5_request', 'writer.close()'), ('/usr/lib64/python2.7/socket.py', 279, 'close', 'self.flush()'), 
    ('/usr/lib64/python2.7/socket.py', 303, 'flush', 'self._sock.sendall(view[write_offset:write_offset+buffer_size])'), 
    ('.../v/lib/python2.7/site-packages/gevent/socket.py', 464, 'sendall', 'data_sent += self.send(_get_memory(data, data_sent), flags, timeout=timeleft)')]```
    
    opened by jekel 7
  • UDP support

    UDP support

    This adds support for sending and receiving UDP packets with a SOCKS5 proxy.

    I reworked the code a fair amount, so that I could reuse some of the existing SOCKS5 code. For instance, _recvall() is now _readall() and works on a socket.makefile() or BytesIO object rather than the raw socket. Let me know if you aren’t comfortable with this refactoring, and I could try to tone it down a bit.

    Another point is that my UDP code only works with Python 3. Python 2’s socket class sets the sendto() etc methods as instance attributes (rather than class attributes), defeating the normal way of overriding methods. I’m not really motivated to make it work for Python 2 unless there is a really simple workaround.

    I should add some tests, but haven’t got around to it. Would you be interested if I converted the test suite to use Python’s standard unittest framework? It should be more maintainable and flexible that way.

    opened by vadmium 7
  • Include sockshandler in pip package maybe?

    Include sockshandler in pip package maybe?

    As you said

    sockshandler.py is just a "recipe"/utility for easy integration with urllib2. So, I don't think there is a need for an__init__.py because socks.py is the only file intended for importion.

    Why not? One can use PySocks just for urllib2 (like I do). So maybe it would be a nice choice to add sockshandler in pip package?

    opened by ov7a 6
  • Support contacting remote hosts via IPv6 literals.

    Support contacting remote hosts via IPv6 literals.

    SOCKS5 adds support for sending literal IPv6 addresses. This patch takes advantage of that support to allow applications using PySocks to request connection to literal IPv6 addresses, and to allow local DNS resolution to resolve IPv6 addresses as well as IPv4 addresses.

    opened by Lukasa 5
  • Avoid DeprecationWarning

    Avoid DeprecationWarning

    Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working.

    Preserves Python 2 compatibility.

    opened by hroncok 4
  • AttributeError using socks5 with requests[socks]

    AttributeError using socks5 with requests[socks]

    Using requests with a socks5 proxy fails on: AttributeError: 'super' object has no attribute 'settimeout'

    Reproduction Steps

    pip install requests[socks]==2.14.2 (this installs PySocks v1.6.7)

    run a socks proxy on port 9050. I use Tor for that matter.

    Simplified code I use is:

    import requests
    proxies={'http': 'socks5://127.0.0.1:9050'}
    url = 'http://www.whatismyip.org/'
    requests.get(url, proxies=proxies)
    

    System Information

    Windows 7 (x64): 6.1.7601
    Python 2.7.12 64bit
    

    Full Traceback

    File "c:\Python27\lib\site-packages\requests\api.py", line 72, in get return request('get', url, params=params, **kwargs) File "c:\Python27\lib\site-packages\requests\api.py", line 58, in request return session.request(method=method, url=url, **kwargs) File "c:\Python27\lib\site-packages\requests\sessions.py", line 518, in request resp = self.send(prep, **send_kwargs) File "c:\Python27\lib\site-packages\requests\sessions.py", line 639, in send r = adapter.send(request, **kwargs) File "c:\Python27\lib\site-packages\requests\adapters.py", line 438, in send timeout=timeout File "c:\Python27\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 600, in urlopen chunked=chunked) File "c:\Python27\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 356, in _make_request conn.request(method, url, **httplib_request_kw) File "c:\python27\Lib\httplib.py", line 1057,in request self._send_request(method, url, body, headers) File "c:\python27\Lib\httplib.py", line 1097, in _send_request self.endheaders(body) File "c:\python27\Lib\httplib.py",line 1053, in endheaders self._send_output(message_body) File "c:\python27\Lib\httplib.py", line 897, in _send_output self.send(msg) File "c:\python27\Lib\httplib.py", line 859,in send self.connect() File "c:\Python27\lib\site-packages\requests\packages\urllib3\connection.py", line 166, in connect conn = self._new_conn() File "c:\Python27\lib\site-packages\requests\packages\urllib3\contrib\socks.py", line 88, in _new_conn **extra_kw File "c:\Python27\lib\site-packages\socks.py", line 229, in create_connection sock.connect((remote_host, remote_port)) File "c:\Python27\lib\site-packages\socks.py", line 96, in wrapper return function(*args, **kwargs) File "c:\Python27\lib\site-packages\socks.py", line 781, in connect super(socksocket, self).settimeout(self._timeout) AttributeError: 'super' object has no attribute 'settimeout'

    Extras

    I want to suggest the closest issue I have found, that is on gevent: https://github.com/gevent/gevent/issues/937

    Replacing all occurences of (in socks.py): super(socksocket, self).settimeout with: self.settimeout solves the issue, but I don't know if there are any other side effects

    opened by dorazouri 4
  • Please Include a CHANGELOG

    Please Include a CHANGELOG

    Tracking changes that might have caused issues in software using this library would be easier with a CHANGELOG, please include one : http://keepachangelog.com/en/0.3.0/.

    opened by mcansky 4
  • `recvfrom` read less than request

    `recvfrom` read less than request

    This problem can be repro by following code:

    import socket
    import socks
    
    BUF_SIZE = 1024
    
    conn = socks.socksocket(socket.AF_INET, socket.SOCK_DGRAM, socket.SOL_UDP)
    conn.set_proxy(socks.SOCKS5, "127.0.0.1", 1080)
    conn.sendto(b'a' * BUF_SIZE, ('127.0.0.1', 8000))
    data, _ = conn.recvfrom(BUF_SIZE)
    # less exact 10 bytes than request
    assert len(data) == BUF_SIZE - 10
    

    This is caused by following lines in recvfrom:

            buf = BytesIO(_BaseSocket.recv(self, bufsize, flags))
            # remain BUF_SIZE - 2
            buf.seek(2, SEEK_CUR)
            # remain BUF_SIZE - 3
            frag = buf.read(1)
            if ord(frag):
                raise NotImplementedError("Received UDP packet fragment")
            # remain BUF_SIZE - 10
            fromhost, fromport = self._read_SOCKS5_address(buf)
    
    opened by loggerhead 4
  • Reset the state ?

    Reset the state ?

    Hi,

    I need to make multiple calls in a script, with or without proxies.

    For now, I do this:

    if proxy:
                socks.set_default_proxy(socks.SOCKS5, proxy, port)
                socket.socket = socks.socksocket
    handler = urlopen(url)
    

    My problem is that I then need to reset socket.socket to prevent using SOCKS proxy for further calls. My method for now is to store socket.socket in a global var before and then to restore it when needed.

    Is there a better way ?

    Maybe calling socks.set_default_proxy() should remove all default proxies. What do you think about it ?

    Thanks

    opened by Phyks 4
  • Update LICENSE wording to fully match BSD-3-Clause

    Update LICENSE wording to fully match BSD-3-Clause

    This adds comma between DATA and OR PROFITS, adds WHETHER IN CONTRACT, STRICT LIABILITY, words, and fixes a typo (DAMANGE -> DAMAGE).

    Reference: https://spdx.org/licenses/BSD-3-Clause.html

    opened by mtelka 0
  • [Errno 60] Operation timed out

    [Errno 60] Operation timed out

    while trying to connect() , it takes some time and throw an Error msg -

    TimeoutError: [Errno 60] Operation timed out
    
    During handling of the above exception, another exception occurred:
    

    socks.GeneralProxyError: Socket error: [Errno 60] Operation timed out

    Solution please

    opened by shaswataddas 0
  • Feature Request: connect to SOCKS/HTTP proxy through unix domain socket

    Feature Request: connect to SOCKS/HTTP proxy through unix domain socket

    Some applications publish SOCKS/HTTP proxy via unix domain socket. For example, TOR creates /run/tor/socks as a SOCKS proxy.

    I think we should able to use PySocks like this:

    import socks
    s = socks.socksocket()
    s.set_proxy(socks.SOCKS5, "/run/tor/socks")        # using unix domain socket /run/tor/socks as proxy
    
    opened by fpemud 0
  • socket.socket.recv vs. socks.socksocket.recv w/o proxy

    socket.socket.recv vs. socks.socksocket.recv w/o proxy

    Hi there,

    while monkeypatching a 3rd-party module, I observed a different behavior when calling socket.socket.recv(0) and socks.socksocket.recv(0). The former call will return b'' but the latter one will just stuck and never return.

    The following code snippet reproduces this issue for me:

    import socket
    import socks
    
    addr = ("127.0.0.1", 80)
    
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect(addr)
    r = s.recv(0)
    print(r)
    
    s1 = socks.socksocket(socket.AF_INET, socket.SOCK_STREAM)
    s1.connect(addr)
    r1 = s1.recv(0)  # never returns!
    print(r1)
    

    I would have expected similar behavior at least when no proxy is used. But I also do not understand what the idea of a recv(0) is, since I have no experience using sockets. So maybe this is as expected?!

    (Python 3.9.12, PySocks 1.7.1)

    Thanks in advance Thomas

    opened by totifra 0
  • Proxy server authentication with token

    Proxy server authentication with token

    Nowadays many proxy servers are authenticating the user by a token or key, instead username and password. Every request shall include the key, in a way similar to: http://myproxyserver.com:51337/?apiKey=bW3ZXxHJdjfodhsfodshfoisdofwe6wjCU

    Is there a way to authenticate with pysocks using such keys?

    opened by sukhoi47 2
Top server mcpe Indonesia!

server_mcpe Top server mcpe Indonesia! install pkg install python pkg install git git clone https://github.com/Latip176/server_mcpe cd server_mcpe pip

Muhammad Latif Harkat 2 Jul 17, 2022
Ov3 - Easy common OpenVPN3 operations

ov3 Easy common OpenVPN3 operations Install ov3 requires Python3 and OpenVPN3 to

Yunus Bora Erciyas 6 Apr 25, 2022
Easy to use gRPC-web client in python

pyease-grpc Easy to use gRPC-web client in python Tutorial This package provides a requests like interface to make calls to gRPC-Web servers.

Sudipto Chandra 4 Dec 03, 2022
JF⚡can - Super fast port scanning & service discovery using Masscan and Nmap. Scan large networks with Masscan and use Nmap's scripting abilities to discover information about services. Generate report.

Description Killing features Perform a large-scale scans using Nmap! Allows you to use Masscan to scan targets and execute Nmap on detected ports with

377 Jan 03, 2023
Terminal based chat - networking project with sockets in python

Terminal based chat - networking project with sockets in python

2 Jan 24, 2022
A simple Encrypted IM chat software Server & client based on Python3.

SecretBox A simple Encrypted IM chat software Server & client based on Python3. Version 1.0 命令行版 安装步骤 Server 运行pip3 install -r requirements 安装依赖。 运行py

h3h3da 5 Oct 31, 2022
A socket script to obtain chinese phones-sequence for any english word

Foreign Pronunciation Generator (English-Chinese) We provide a simple socket script for acquiring Chinese pronunciation of English words (phones in ai

Ephemeroptera 5 Jul 25, 2022
A TrueCharts automatic and bulk update utility

trueupdate A TrueCharts automatic and bulk update utility How to install run pip install trueupdate Please be aware you will need to reinstall after e

TrueCharts 125 Jan 04, 2023
Simple self-hosted server to receive files from remote systems

Badtray This is a very simple self-hosted server to receive files from remote systems. This works similar to Bintray (RIP) and primarily designed to d

Alex Taradov 1 Nov 22, 2021
An opensource library to use SNMP get/bulk/set/walk in Python

SNMP-UTILS An opensource library to use SNMP get/bulk/set/walk in Python Features Work with OIDS json list [Find Here](#OIDS List) GET command SET com

Alexandre Gossard 3 Aug 03, 2022
This script will make it easier to connect to any wireguard vpn config

wireguard-linux-python-script-vpn This script will make it easier to connect to any wireguard vpn config also u will need your wireguard vpn from your

Jimo 1 Sep 21, 2022
Compare the contents of your hosted and proxy repositories for coordinate collisions

Nexus Repository Manager dependency/namespace confusion checker This repository contains a script to check if you have artifacts containing the same n

Sonatype Community 59 Mar 31, 2022
Python module to interface with Tuya WiFi smart devices

TinyTuya Python module to interface with Tuya WiFi smart devices Description This python module controls and monitors Tuya compatible WiFi Smart Devic

Jason Cox 365 Dec 26, 2022
A protocol or procedure that connects an ever-changing IP address to a fixed physical machine address

p0znMITM ARP Poisoning Tool What is ARP? Address Resolution Protocol (ARP) is a protocol or procedure that connects an ever-changing IP address to a f

Furkan OZKAN 9 Sep 18, 2022
PyBERT is a serial communication link bit error rate tester simulator with a graphical user interface (GUI).

PyBERT PyBERT is a serial communication link bit error rate tester simulator with a graphical user interface (GUI). It uses the Traits/UI package of t

David Banas 59 Dec 23, 2022
IP Pinger - This tool allows you to enter an IP and check if its currently connected to a host

IP Pinger - This tool allows you to enter an IP and check if its currently connected to a host

invasion 3 Feb 18, 2022
A Python framework for interacting with Solana's Pyth network.

Pyth Network A basic Python framework for reading and decoding data regarding the Pyth network

1 Nov 29, 2021
Simple HTTP Server for CircuitPython

Introduction Simple HTTP Server for CircuitPython Dependencies This driver depen

Adafruit Industries 22 Jan 06, 2023
Simple local RPG turn-based to play while learn something using the anki system

Simple local RPG turn-based to play while learn something using the anki system

Raphael Kieling 5 Aug 02, 2022
Py script to aid in setting up the boot chime in OpenCore.

BootChime Py script to aid in setting up the boot chime in OpenCore. It does so by helping you locate your IOHDACodecDevices, IOHDACodecAddress values

CorpNewt 7 Sep 19, 2022