{"id":13775873,"url":"https://github.com/igrigorik/em-socksify","last_synced_at":"2025-04-13T10:52:41.987Z","repository":{"id":1340530,"uuid":"1286525","full_name":"igrigorik/em-socksify","owner":"igrigorik","description":"Transparent proxy support for any EventMachine protocol","archived":false,"fork":false,"pushed_at":"2018-09-25T19:29:26.000Z","size":33,"stargazers_count":31,"open_issues_count":1,"forks_count":11,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-05-08T18:35:36.891Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/igrigorik.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-01-24T03:45:35.000Z","updated_at":"2024-03-07T19:33:51.000Z","dependencies_parsed_at":"2022-07-07T01:01:54.334Z","dependency_job_id":null,"html_url":"https://github.com/igrigorik/em-socksify","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igrigorik%2Fem-socksify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igrigorik%2Fem-socksify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igrigorik%2Fem-socksify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igrigorik%2Fem-socksify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/igrigorik","download_url":"https://codeload.github.com/igrigorik/em-socksify/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248703000,"owners_count":21148116,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T17:01:53.159Z","updated_at":"2025-04-13T10:52:41.950Z","avatar_url":"https://github.com/igrigorik.png","language":"Ruby","funding_links":[],"categories":["\u003ca id=\"d03d494700077f6a65092985c06bf8e8\"\u003e\u003c/a\u003e工具"],"sub_categories":["\u003ca id=\"57b8e953d394bbed52df2a6976d98dfa\"\u003e\u003c/a\u003eSocks"],"readme":"# Transparent proxy support for any EventMachine protocol\n\nDealing 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.\n\n### Example: Routing HTTP request via SOCKS5 proxy\n\n```ruby\nclass Handler \u003c EM::Connection\n  include EM::Socksify\n\n  def connection_completed\n    socksify('google.ca', 80) do\n      send_data \"GET / HTTP/1.1\\r\\nConnection:close\\r\\nHost: google.ca\\r\\n\\r\\n\"\n    end\n  end\n\n  def receive_data(data)\n    p data\n  end\nend\n\nEM.run do\n  EventMachine.connect SOCKS_HOST, SOCKS_PORT, Handler\nend\n```\n\nWhat'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.\n\nsocksify 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.\n\nFor SOCKS proxies which require authentication, use:\n\n```ruby\nsocksify(destination_host, destination_port, username, password, version)\n```\n\n### Example: Routing HTTPS request via a squid CONNECT proxy\n\n```ruby\nclass Handler \u003c EM::Connection\n  include EM::Connectify\n\n  def connection_completed\n    connectify('www.google.ca', 443) do\n      start_tls\n      send_data \"GET / HTTP/1.1\\r\\nConnection:close\\r\\nHost: www.google.ca\\r\\n\\r\\n\"\n    end\n  end\n\n  def receive_data(data)\n    p data\n  end\nend\n\nEM.run do\n  EventMachine.connect PROXY_HOST, PROXY_PORT, Handler\nend\n```\n\nFor CONNECT proxies which require authentication, use:\n\n```ruby\nconnectify(destination_host, destination_port, username, password)\n```\n\n### Wishlist\n\n- IPV6 support\n- SOCKS4 support\n\n### Resources\n\n- [SOCKS on Wikipedia](http://en.wikipedia.org/wiki/SOCKS)\n- [Socksify-Ruby](https://github.com/astro/socksify-ruby) for regular Ruby TCPSocket\n- [HTTP Connect Tunneling](http://en.wikipedia.org/wiki/HTTP_tunnel#HTTP_CONNECT_Tunneling)\n\n### Contributors\n\n- [Ilya Grigorik](https://github.com/igrigorik)\n- [Conrad Irwin](https://github.com/ConradIrwin)\n\n### License\n\n(The MIT License)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figrigorik%2Fem-socksify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Figrigorik%2Fem-socksify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figrigorik%2Fem-socksify/lists"}