socks5 | SOCKSv5 bring your own IO library | Proxy library

 by   mike820324 Python Version: 0.2.1 License: MIT

kandi X-RAY | socks5 Summary

kandi X-RAY | socks5 Summary

socks5 is a Python library typically used in Networking, Proxy applications. socks5 has no bugs, it has build file available, it has a Permissive License and it has low support. However socks5 has 4 vulnerabilities. You can install using 'pip install socks5' or download it from GitHub, PyPI.

socks5 is a small module SOCKS version 5 library written fom scratch in Python, which is highly inspired by h11 and hyper-h2. It's a "bring-your-own-IO" library; that is socks5 module does not contain any network related code. socks5 only deal with the parsing and state management of the socks5 connection, the underlying IO part is not cover in the internal code. Currently, socks5 module support the following protocol and rfc.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              socks5 has a low active ecosystem.
              It has 25 star(s) with 3 fork(s). There are 2 watchers for this library.
              OutlinedDot
              It had no major release in the last 12 months.
              There are 4 open issues and 13 have been closed. On average issues are closed in 12 days. There are 2 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of socks5 is 0.2.1

            kandi-Quality Quality

              socks5 has 0 bugs and 0 code smells.

            kandi-Security Security

              OutlinedDot
              socks5 has 4 vulnerability issues reported (0 critical, 4 high, 0 medium, 0 low).
              socks5 code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              socks5 is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              socks5 releases are not available. You will need to build from source code and install.
              Deployable package is available in PyPI.
              Build file is available. You can build the component from source.
              Installation instructions are not available. Examples and code snippets are available.
              socks5 saves you 793 person hours of effort in developing the same functionality from scratch.
              It has 1822 lines of code, 212 functions and 29 files.
              It has medium code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed socks5 and discovered the below as its top functions. This is intended to give you an instant insight into socks5 implemented functionality, and help decide if they suit your requirements.
            • Handle socks5 message
            • Receive data from the socket
            • Send event to server
            • Receive data from the server
            • Construct an AuthResponse from data
            • Send an event to the server
            • Create an AuthResponse from an event
            • Do the socks protocol
            • Connects to a given host and port
            Get all kandi verified functions for this library.

            socks5 Key Features

            No Key Features are available at this moment for socks5.

            socks5 Examples and Code Snippets

            socks5:,Quick Guide:
            Pythondot img1Lines of Code : 33dot img1License : Permissive (MIT)
            copy iconCopy
            from socks5 import Connection
            client_conn = Connection(our_role="client")
            client_conn.initiate_connection()
            
            server_conn = Connection(our_role="server")
            server_conn.initiate_connection()
            
            from socks5 import GreetingRequest, GreetingResponse
            from sock  
            Events:
            Pythondot img2Lines of Code : 32dot img2License : Permissive (MIT)
            copy iconCopy
            event = Socks4Request(REQ_COMMAND["CONNECT"], "192.168.0.1", 5580, "Johnny")
            
            # Socks4a domainname support
            event = Socks4Request(REQ_COMMAND["CONNECT"], "0.0.0.1", 5580, "Johnny", "www.google.com")
            
            event = Socks4Response(RESP_STATUS["REQUEST_GRANTED  
            socks5:,Installation:
            Pythondot img3Lines of Code : 5dot img3License : Permissive (MIT)
            copy iconCopy
            pip install socks5
            
            # follow the latest version
            git clone https://github.com/mike820324/socks5
            cd socks5 && pip install -U .
              
            Python with Proxy
            Pythondot img4Lines of Code : 14dot img4License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            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(so
            Using proxy with Chromedriver within Google Cloud Engine
            Pythondot img5Lines of Code : 42dot img5License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            from selenium import webdriver
            from selenium.webdriver.chrome.options import Options
            
            proxy_server = '207.157.25.44:80'
            
            chrome_options = Options()
            chrome_options.add_argument("--disable-infobars")
            chrome_options.add_argument("start-maximi
            Pip won't let me install anything
            Pythondot img6Lines of Code : 2dot img6License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            pip install 
            
            Pip won't let me install anything
            Pythondot img7Lines of Code : 3dot img7License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            HTTP_PROXY=http://10.8.0.1:8080
            HTTPS_PROXY=http://10.8.0.1:8080
            
            Porting Python2 script to Python3 - struct library
            Pythondot img8Lines of Code : 95dot img8License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            #!/usr/bin/python3
            
            import socket
            import struct
            
            ICMP_ECHO = 0
            ICMP_ECHO_REQUEST = 8
            
            class ICMPPacket(object):
                def __init__(self, type, code, checksum, id,
                             sequence, data, source_ip, dest=(None, None)):
                    self.t
            Python undetected-chromebrowser suddenly not working on bet365.com
            Pythondot img9Lines of Code : 7dot img9License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            undetected_chromedriver.install(
                executable_path='c:/users/user1/chromedriver.exe',
            )
            
            opts = uc.ChromeOptions()
            opts.add_argument(f'--proxy-server=socks5://127.0.0.1:9050')
            
            Connect to SSH server through SOCKS5 proxy
            Pythondot img10Lines of Code : 26dot img10License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            def createSSHClient(server, port, user):
                
                sock=socks.socksocket()
                sock.set_proxy(
                    proxy_type=socks.SOCKS5,
                    addr='10.0.0.2',
                    port=1080,
                    username=base64.b64decode('dXNlcg==').decode("utf-8"),
                 

            Community Discussions

            QUESTION

            Privoxy does not work with traffic from iptables
            Asked 2022-Apr-02 at 11:45

            I have privoxy configured and working on port 8118. I can forward HTTP and HTTPS traffic when defining the http_proxy and https_proxy variables to point out to the proxy. Examples:

            ...

            ANSWER

            Answered 2022-Apr-02 at 11:45

            I'm not entirely familiar with how Privoxy works, however I do know how intercepting proxy works on Linux.
            HTTP proxies and intercepting proxies work in very different ways. An HTTP proxy get the destination from the first line of the query, which would contain the domain name (e.g. it should be GET http://www.google.com/ HTTP/1.1). For HTTPS, it does an HTTP CONNECT request with the domain:port to connect to (e.g. CONNECT www.google.com:443 HTTP/1.1).
            An intercepting proxy get the original destination address from the kernel by doing a getsockopt() with some specific parameters. It has no knowledge of higher level protocol.
            In general redirecting with iptables a request to an HTTP proxy does not work because of theses differences. That said, Privoxy seems to have a configuration option accept-intercepted-requests that you can use so it read the target from the Host: HTTP header. With that configuration, it should be able to handle HTTP requests redirected using iptables. As the documentation says, this is not supported for HTTPS. You will need to use some additional software which can do the forwarding to an HTTP proxy, probably much like Proxifier does. I know moproxy can do that. It ought to not be the only one, but I don't know others.

            Additional questions:

            • Why setting the variables works, and through iptables doesn't?

            because HTTP and transparent/intercepting proxy works in different ways. When the variables are present, curl (and other) alter how they send the query, but with iptables, they don't (as they don't know you use a proxy).

            • Why do I have to set the https_proxy to point to http://...? Is that privoxy-related?

            the http:// in your environment variable is to describe how you connect to the proxy (it could actually be https:// if your proxy had a tls certificate, and it would work with http requests too, though they would be encrypted only from you to the proxy, not from the proxy to the remote server).

            • Regarding the comment "HTTPS is not supposed to be used with transparent proxies": So how does Proxifier work on Windows? If that is not transparent a proxy, is there another term for it? Why can't we have something similar on WSL/Linux?

            I don't know the specifics of how transparent proxies work on Windows. Assuming it works a lot like Linux, Proxifier probably redirect the request to a local port, get the actual destination, wrap the data in a way it's understood by HTTP/SOCKS proxy and send that to the proxy you told it to use. Maybe the capture part is a bit different (creating a new network interface, ask Windows to send the traffic their, reconstruct the stream from raw tcp packets, wrap the data). This is often called transparent proxy as the client doesn't know a proxy is used, some call it an intercepting proxy instead. And we can have something similar, moproxy is an example (probably not the only one)

            Source https://stackoverflow.com/questions/71709157

            QUESTION

            Setting proxies when crawling websites with Python
            Asked 2022-Mar-12 at 18:30

            I want to set proxies to my crawler. I'm using requests module and Beautiful Soup. I have found a list of API links that provide free proxies with 4 types of protocols.

            All proxies with 3/4 protocols work (HTTP, SOCKS4, SOCKS5) except one, and thats proxies with HTTPS protocol. This is my code:

            ...

            ANSWER

            Answered 2021-Sep-17 at 16:08

            I did some research on the topic and now I'm confused why you want a proxy for HTTPS.

            While it is understandable to want a proxy for HTTP, (HTTP is unencrypted) HTTPS is secure.

            Could it be possible your proxy is not connecting because you don't need one?

            I am not a proxy expert, so I apologize if I'm putting out something completely stupid.

            I don't want to leave you completely empty-handed though. If you are looking for complete privacy, I would suggest a VPN. Both Windscribe and RiseUpVPN are free and encrypt all your data on your computer. (The desktop version, not the browser extension.)

            While this is not a fully automated process, it is still very effective.

            Source https://stackoverflow.com/questions/69064792

            QUESTION

            Failed to connect to shadowsocks client
            Asked 2022-Feb-07 at 17:10

            I've configured shadowsocks system by running ss-server on VPS and ss-local on my client machine. Then I made a simple SOCKS5 client which connects to ss-local and resolve SOCKS request using C. All work well, when I run ss-tunnel instead of ss-local, my SOCKS5 client can't connect to ss-tunnel.

            TCP connection terminates as soon as it established. I'm not sure what is the proper reason.

            ...

            ANSWER

            Answered 2022-Feb-07 at 17:10

            ss-tunnel establishes a complete tunnel with ss-server, all traffic to ss-tunnel is directly relayed to ss-server without any SOCKS request/resolve processes. After I've removed SOCKS handshake in my client program, it worked properly.

            Source https://stackoverflow.com/questions/70994692

            QUESTION

            HTTPS over Socks5 server implementation
            Asked 2022-Jan-01 at 04:00

            I am trying to implement a Socks5 server that could relay both HTTP and HTTPS traffic.

            As the RFC1928 mentions, the following steps to establish a connection and forward the data must be taken :

            1. Client sends a greeting message to the proxy.
            2. Client & proxy authentication (assuming it is successful).
            3. Client sends a request to the proxy to connect to the destination.
            4. The proxy connects to the destination and sends back a response to the client to indicate a successful open tunnel.
            5. The proxy reads the data from the client and forwards it to the destination.
            6. The proxy reads the data from the destination and forwards it to the client.

            So far, the proxy works as it should. It is able to relay HTTP traffic using its basic data forwarding mechanism. However, any request from the client to an HTTPS website will be aborted because of SSL/TLS encryption.

            Is there another sequence/steps that should be followed to be able to handle SSL/TLS (HTTPS) traffic?

            ...

            ANSWER

            Answered 2022-Jan-01 at 04:00

            The sequence you have described is correct, even for HTTPS. When the client wants to send a request to an HTTPS server through a proxy, it will request the proxy to connect to the target server's HTTPS port, and then once the tunnel is established, the client will negotiate a TLS handshake with the target server, then send an (encrypted) HTTP request and receive an (encrypted) HTTP response. The tunnel is just a passthrough of raw bytes, the proxy has no concept of any encryption between the client and server. It doesn't care what the bytes represent, its job is just to pass them along as-is.

            Source https://stackoverflow.com/questions/70546537

            QUESTION

            How SOCKS5 infers the destination port within SSH dynamic forwarding?
            Asked 2021-Dec-31 at 17:54

            When using local forwarding we are free to pick destination port:

            ssh -L 8000:10.10.1.11:80 user@192.168.56.102 - 80 is destination port - we explicitly specify which port to forward to.

            Take a look at diagram in this article. If I understand correctly, in dynamic forwarding destination port is somewhat implicit (?):

            ssh -D 8080 user@192.168.56.102 - 8080 is local host port, but still it somehow forwards to 80 for us.

            Questions:

            • How SOCKS5 proxy knows which port to forward traffic to?
            • Does SOCKS5 proxy somehow sniff destination from the protocol of the traffic it proxies?
            • Can that destination port be configured?
            • Where is it configured - on my local machine, or remote that does final forwarding for us? Nowhere?
            • Is it a predefined fixed set of protocols/ports? Smth like http=80 destination port?
            • Any other internal details of forwarding you can add to clarify the picture.

            thanks.

            PS. Here https://unix.stackexchange.com/questions/213213/difference-between-local-port-forwarding-and-dynamic-port-forwarding#comment401063_213219 i found some hint to what i'm interested in, pity there are no details provided...

            ...

            ANSWER

            Answered 2021-Dec-31 at 17:54

            SSH and SOCKS are two completely different and unrelated protocols. But, to answer your questions:

            How SOCKS5 proxy knows which port to forward traffic to?

            A SOCKS client explicitly tells it where to connect. The destination host/ip and port are input fields in the SOCKS CONNECT command. So, there is no guessing/infering at all.

            Does SOCKS5 proxy somehow sniff destination from the protocol of the traffic it proxies?

            No. SOCKS is just a tunnel of raw bytes, it has no concept of protocols beyond its own.

            Can that destination port be configured?

            Not on the proxy itself, no. Since the client decides where to connect, any configuration would be on the client side.

            Is it a predefined fixed set of protocols/ports? Smth like http=80 destination port?

            No.

            Any other internal details of forwarding you can add to clarify the picture.

            Read the SOCKS protocol specs.

            SOCKS v4: https://www.openssh.com/txt/socks4.protocol

            SOCKS v4a: https://www.openssh.com/txt/socks4a.protocol

            SOCKS v5: https://datatracker.ietf.org/doc/html/rfc1928

            Source https://stackoverflow.com/questions/70527985

            QUESTION

            Expose client behind NAT to internet by using a public reverse-proxy (with access to the internet)
            Asked 2021-Dec-14 at 23:32

            I want to understand the theory of exposing clients behind NATs via a public server, for example to use the client as a proxy (preferably SOCKS5). It would be ideal to find a ready solution but theory would good enough.

            To point out what I mean. The client behind the NAT does not directly listen on TCP. It just opens up a TCP connection to the public server which should expose the client. The SOCKS5 proxy on client behind NAT is not directly exposed so the dialed TCP connection should somehow behave like a TCP listener.

            If a client behind NAT connects to a public server, how do other users connect and how should I forward the requests?

            I think basically it's the same technique that TeamViewer is using:

            "When establishing a session, TeamViewer determines the optimal type of connection. After the handshake through our master servers, a direct connection via UDP or TCP is established in 70% of all cases (even behind standard gateways, NATs and firewalls). The rest of the connections are routed through our highly redundant router network via TCP or https tunneling. You do not have to open any ports in order to work with TeamViewer."

            But how exactly?

            ...

            ANSWER

            Answered 2021-Dec-14 at 23:32

            To summarize, for a proxy server in golang, you have to

            1. Create a server that listens to requests with some parameters.
            2. When a request is received, it will make the request to the desired address.
            3. Then it will return the response to the original client in the private network.

            Source https://stackoverflow.com/questions/70356041

            QUESTION

            Why socks5 UDP association terminates when the TCP connection that the UDP ASSOCIATE request arrived on terminates?
            Asked 2021-Dec-14 at 09:40

            As socks5 rfc says,

            A UDP association terminates when the TCP connection that the UDP ASSOCIATE request arrived on terminates.

            I wonder, doesn't "the TCP connection that the UDP ASSOCIATE request arrived on" just terminate when it timeouts? As there is no more data need to be sent in that TCP connection.

            Should the client send meaningless data in that TCP connection just to keep it alive while it need the UDP association?

            ...

            ANSWER

            Answered 2021-Dec-14 at 09:40

            I wonder, doesn't "the TCP connection that the UDP ASSOCIATE request arrived on" just terminate when it timeouts?

            No. The TCP connection is kept alive as a signal that the proxied UDP socket is still valid. Without it, the client has no way of knowing whether the server is still reachable or whether the UDP socket is still allocated.

            Similarly, without the TCP connection the server has no other way of knowing whether the client is still connected.

            Should the client send meaningless data in that TCP connection just to keep it alive while it need the UDP association?

            There's no need to send meaningless data. Just keep the connection alive. TCP has a built-in keepalive mechanism which can be turned on.

            Edit: It's worth pointing out that the default TCP keepalive times on both Linux and Windows is fairly long. See this question on ways of tweaking it for specific sockets.

            Source https://stackoverflow.com/questions/70331639

            QUESTION

            Connecting a proxy to a Python script using the Telethon module
            Asked 2021-Dec-14 at 07:38

            I need to get the proxy from the proxy.txt file:

            ...

            ANSWER

            Answered 2021-Dec-14 at 07:38

            Not sure about HTTP proxy or others, but you can use MTPROTO proxy with super ease:

            Source https://stackoverflow.com/questions/70335584

            QUESTION

            Find a p tag with a partial string using beautifulsoup, and extract the integer in the string of the p tag that follows
            Asked 2021-Dec-11 at 16:53

            Trying to build an iteration that goes through weblinks in order to extract the integer that is in the p tag that follows the p tag that contains the words "AGGREGATE AMOUNT BENEFICIALLY OWNED BY EACH REPORTING PERSON". The target pages have close enough patterns but are not identical. That AGGREGATE AMOUNT sentence is not formatted identically (sometimes capitalized, sometimes not, and spacing might not be identical). I included 3 examples below on the section I am trying to extract the integer value from.

            Below are the steps I am trying to achieve:

            1-Iterate through links Some links: https://www.sec.gov/Archives//edgar/data/29669/000119312521353247/d228949dsc13da.htm https://www.sec.gov/Archives//edgar/data/1482018/000119312521353071/d258656dsc13d.htm https://www.sec.gov/Archives//edgar/data/1590854/000119312521353064/d210475dsc13d.htm https://www.sec.gov/Archives//edgar/data/1021944/000119312521353050/d243715dsc13g.htm https://www.sec.gov/Archives//edgar/data/1609492/000119312521353003/d251372dsc13da.htm ...

            2-Find p tag that contains partial words "AGGREGATE AMOUNT BENEFICIALLY", which can be small caps , titled, or all caps

              Aggregate Amount Beneficially Owned by Each Reporting Person:

            3-Once the p tag found, continue to look in the following p tags until we get to the first p tag where the string (if exists), stripped of its commas is an integer (not empty).This can be the immediate p tag that follows, or the one after as in the code below.

            10,927,100*

            10,927,100 is the number I need, although it needs to be stripped from its commas (I know we can use the code below), but the string needs to be stripped from any other characters that are not numbers as well... int(shares.replace(',', '')

            example1:

            ...

            ANSWER

            Answered 2021-Dec-11 at 15:07

            You should be able to adapt this. The pages you're visiting are very plain HTML (no Javascript) so it's very simple and efficient just to process the page in a simple loop.

            What happens here is that we look for a p tag with text matching "AGGREGATE AMOUNT BENEFICIALLY OWNED BY EACH REPORTING PERSON" in a case-insensitive manner. If we find that, we set a flag. Then on subsequent iterations of the p tags found by BeautifulSoup, we look for text that is a) not empty and b) contains a sequence of digits (ignoring commas).

            And so on...

            Source https://stackoverflow.com/questions/70315876

            QUESTION

            Is there a native support for proxy connection via socks5 for boost::asio?
            Asked 2021-Oct-30 at 19:44

            I'm using boost::asio to handle network communication between my program and remote server. To establish a connection with a server I do the following sequence of operations:

            ...

            ANSWER

            Answered 2021-Oct-30 at 19:36

            I went ahead with the finger exercise and implemented socks5.hpp like I did before for socks4: socks4 with asynchronous boost::asio

            Without further ado:

            Source https://stackoverflow.com/questions/69778112

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            Buffer overflow in libsocks5 library of Socks 5 (socks5) 1.0r5 allows local users to gain privileges via long environmental variables.
            Buffer overflow in socks5 server on Linux allows attackers to execute arbitrary commands via a long connection request.
            Multiple buffer overflows in NEC SOCKS5 1.0 r11 and earlier allow remote attackers to cause a denial of service and possibly execute arbitrary code via a long username to (1) the GetString function in proxy.c for the SOCKS5 module or (2) the HandleS4Connection function in proxy.c for the SOCKS4 module.
            Off-by-one buffer overflow in NEC SOCKS5 1.0 r11 and earlier allows remote attackers to cause a denial of service and possibly execute arbitrary code via a long hostname.

            Install socks5

            You can install using 'pip install socks5' or download it from GitHub, PyPI.
            You can use socks5 like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            Install
          • PyPI

            pip install socks5

          • CLONE
          • HTTPS

            https://github.com/mike820324/socks5.git

          • CLI

            gh repo clone mike820324/socks5

          • sshUrl

            git@github.com:mike820324/socks5.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link

            Explore Related Topics

            Consider Popular Proxy Libraries

            frp

            by fatedier

            shadowsocks-windows

            by shadowsocks

            v2ray-core

            by v2ray

            caddy

            by caddyserver

            XX-Net

            by XX-net

            Try Top Libraries by mike820324

            microProxy

            by mike820324Python

            ComicReader

            by mike820324JavaScript

            pyfuse-cffi

            by mike820324Python

            microProxy-GUI

            by mike820324JavaScript

            TinyHttpServer

            by mike820324C