-
-
Notifications
You must be signed in to change notification settings - Fork 842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement SOCKS v4, v5 Proxy #203
Comments
So the issue with this is that there's no sans-I/O implementation of the SOCKv4 and SOCKSv5 protocols that doesn't require us to add 3 dependencies. The protocols are so simple that I'm actually in favor of writing our own library that has no dependencies. |
I'm happy to lend a hand on this @sethmlarson. Does it depend on #259? |
Thanks @yeraydiazdiaz! ❤️ It'll definitely intersect on the configuration stage on the client but the dispatcher implementation is separate, let's start by getting a sans-I/O implementation of SOCKSv4 and v5 w/o dependencies and go from there. I actually think that the sans-I/O implementation should be it's own library, maybe on the python-http org, but it can start on one of our personal accounts. Would you like to be the originator or should I create a repo and add you and you can take it from there? |
I'll definitely need some help so it might be easier if it's all setup in non-personal repo from the start 🙂 |
I pushed the initial commit: https://github.com/sethmlarson/socks The repo will live under python-http once we release for the first time! |
while waiting for the implementation, this is a temporary alternative for people who want to use socks4/5 with httpx by using pysocks : # pip install PySocks
import httpx
import socks
import socket
socks.set_default_proxy(socks.SOCKS5, "127.0.0.1", 9050)
socket.socket = socks.socksocket
URL = 'http://ifconfig.me/ip'
with httpx.Client() as client:
resp = client.get(URL)
print(resp.text) |
If it's relevant, there is 3rd party SOCKS implementation: httpx-socks |
It looks like that one doesnt support |
Trio support added in version 0.2.0 |
I wrote a small PoC with Working with the PoC, I added new method to If this idea ( |
@cdeler From what I understand, SOCKS is an application-level protocol that sits on top of TCP (well, there's UDP in SOCKS5, but that's not something we should be thinking about for now), so in theory we shouldn't really need a new type of Also, since I don't think it's been linked to here yet — @yeraydiazdiaz had started a lovely piece of work on HTTPCore already a few months back, based on the So perhaps, if anyone's interested, there'd be room for getting that work up to date. I personally think |
@florimondmanca On one hand you are right, proxy works on L7, but it is a transport for us... Well in terms of You can check what I've done here: encode/httpcore#186 (I've created a PR just to show an idea) I'd like to have a chance to check encode/httpcore#51 :-) Thank you for the advice Update: looks like @yeraydiazdiaz has the same problem as me with https connection |
@florimondmanca you are right, |
I wonder what we should do with Lets imagine that someone wants to access |
Some socks5 servers also don't support DNS resolving. On the other hand, some socks4 servers support it.
See how it is implemented in python-socks which httpx-socks is based on. For asyncio backend you can also use aiodns. |
python-hyper/hyper#441 may be related (though it is for hyper) |
Thank u and hope the implementation will come up to soon |
I wrote a socks library. It has no dependencies and supports sync, async and sans IO usage. I had to write because I want to use over 'unix domain sockets' which none of the other packages supported. (I didn't know about socksio when I wrote but the usage is much simpler). Feel free to depend on it or just copy relevant parts of it. |
Alrighty - closed via encode/httpcore#478 and #2034 using Seth's fantastic We've only got SOCKS5 in right now. Not obvs to me how much value there would be in 4/4a, or in SOCKS5 with the IP resolved by the client. Probably makes sense to leave a decision on those pending user feedback. |
Wow! This is awesome! socks5h would be very useful for me for Tor .onion support. Edit: I might be misunderstanding. Is the IP resolved by the socks5 server? So SOCKS5 with client-side resolution is not supported? |
Correct. That is the current setup. |
That seems like something that's a valid enough use-case to open an issue for. You'd be very welcome to do that, and reference this comment. I had a quick read up about this to educate myself, and found this blog post to be pretty helpful. |
That's perfect for me! I had some code using |
That would probably be a nice feature / change in behaviour to have, yup, but it's a little bit involved to implement. |
Sorry - slow me down I'm being a bit stupid. Our current behaviour is that the proxy resolves the DNS. ( |
Related: #36
The text was updated successfully, but these errors were encountered: