Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/igrigorik/em-socksify
Transparent proxy support for any EventMachine protocol
https://github.com/igrigorik/em-socksify
Last synced: 3 months ago
JSON representation
Transparent proxy support for any EventMachine protocol
- Host: GitHub
- URL: https://github.com/igrigorik/em-socksify
- Owner: igrigorik
- Created: 2011-01-24T03:45:35.000Z (almost 14 years ago)
- Default Branch: master
- Last Pushed: 2018-09-25T19:29:26.000Z (about 6 years ago)
- Last Synced: 2024-05-08T18:35:36.891Z (6 months ago)
- Language: Ruby
- Homepage:
- Size: 32.2 KB
- Stars: 31
- Watchers: 4
- Forks: 11
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-network-stuff - **28**星
README
# Transparent proxy support for any EventMachine protocol
Dealing with SOCKS and HTTP proxies is a pain. EM-Socksify provides a simple ship to setup and negotiation a SOCKS / HTTP connection for any EventMachine protocol.
### Example: Routing HTTP request via SOCKS5 proxy
```ruby
class Handler < EM::Connection
include EM::Socksifydef connection_completed
socksify('google.ca', 80) do
send_data "GET / HTTP/1.1\r\nConnection:close\r\nHost: google.ca\r\n\r\n"
end
enddef receive_data(data)
p data
end
endEM.run do
EventMachine.connect SOCKS_HOST, SOCKS_PORT, Handler
end
```What's happening here? First, we open a raw TCP connection to the SOCKS proxy. Once the TCP connection is established, EventMachine calls the **connection_completed** method in our handler, at which point we call the helper method (**socksify**) with the actual destination and host and port (address that we actually want to get to), and the module does the rest.
socksify temporarily intercepts your receive_data callbacks, negotiates the SOCKS connection (version, authentication, etc), and then once all of that is done, returns control back to your code.
For SOCKS proxies which require authentication, use:
```ruby
socksify(destination_host, destination_port, username, password, version)
```### Example: Routing HTTPS request via a squid CONNECT proxy
```ruby
class Handler < EM::Connection
include EM::Connectifydef connection_completed
connectify('www.google.ca', 443) do
start_tls
send_data "GET / HTTP/1.1\r\nConnection:close\r\nHost: www.google.ca\r\n\r\n"
end
enddef receive_data(data)
p data
end
endEM.run do
EventMachine.connect PROXY_HOST, PROXY_PORT, Handler
end
```For CONNECT proxies which require authentication, use:
```ruby
connectify(destination_host, destination_port, username, password)
```### Wishlist
- IPV6 support
- SOCKS4 support### Resources
- [SOCKS on Wikipedia](http://en.wikipedia.org/wiki/SOCKS)
- [Socksify-Ruby](https://github.com/astro/socksify-ruby) for regular Ruby TCPSocket
- [HTTP Connect Tunneling](http://en.wikipedia.org/wiki/HTTP_tunnel#HTTP_CONNECT_Tunneling)### Contributors
- [Ilya Grigorik](https://github.com/igrigorik)
- [Conrad Irwin](https://github.com/ConradIrwin)### License
(The MIT License)