{"id":13403471,"url":"https://github.com/mscdex/socksv5","last_synced_at":"2025-05-15T03:07:34.889Z","repository":{"id":18579163,"uuid":"21782380","full_name":"mscdex/socksv5","owner":"mscdex","description":"SOCKS protocol version 5 server and client implementations for node.js","archived":false,"fork":false,"pushed_at":"2024-01-18T05:15:18.000Z","size":93,"stargazers_count":401,"open_issues_count":36,"forks_count":120,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-04-30T07:40:33.378Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mscdex.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2014-07-13T03:50:39.000Z","updated_at":"2025-03-04T09:05:00.000Z","dependencies_parsed_at":"2024-04-24T06:08:11.454Z","dependency_job_id":null,"html_url":"https://github.com/mscdex/socksv5","commit_stats":{"total_commits":43,"total_committers":4,"mean_commits":10.75,"dds":0.06976744186046513,"last_synced_commit":"a92b29fa30719074a083453bca4fcad6ee7d442b"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mscdex%2Fsocksv5","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mscdex%2Fsocksv5/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mscdex%2Fsocksv5/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mscdex%2Fsocksv5/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mscdex","download_url":"https://codeload.github.com/mscdex/socksv5/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253074214,"owners_count":21849719,"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-07-30T19:01:30.384Z","updated_at":"2025-05-15T03:07:29.872Z","avatar_url":"https://github.com/mscdex.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","\u003ca id=\"d03d494700077f6a65092985c06bf8e8\"\u003e\u003c/a\u003e工具"],"sub_categories":["\u003ca id=\"57b8e953d394bbed52df2a6976d98dfa\"\u003e\u003c/a\u003eSocks"],"readme":"Description\n===========\n\nSOCKS protocol version 5 server and client implementations for node.js\n\n\nRequirements\n============\n\n* [node.js](http://nodejs.org/) -- v0.10.0 or newer\n\n\nInstall\n=======\n\n    npm install socksv5\n\n\nExamples\n========\n\n* Server with no authentication and allowing all connections:\n\n```javascript\nvar socks = require('socksv5');\n\nvar srv = socks.createServer(function(info, accept, deny) {\n  accept();\n});\nsrv.listen(1080, 'localhost', function() {\n  console.log('SOCKS server listening on port 1080');\n});\n\nsrv.useAuth(socks.auth.None());\n```\n\n* Server with username/password authentication and allowing all (authenticated) connections:\n\n```javascript\nvar socks = require('socksv5');\n\nvar srv = socks.createServer(function(info, accept, deny) {\n  accept();\n});\nsrv.listen(1080, 'localhost', function() {\n  console.log('SOCKS server listening on port 1080');\n});\n\nsrv.useAuth(socks.auth.UserPassword(function(user, password, cb) {\n  cb(user === 'nodejs' \u0026\u0026 password === 'rules!');\n}));\n```\n\n* Server with no authentication and redirecting all connections to localhost:\n\n```javascript\nvar socks = require('socksv5');\n\nvar srv = socks.createServer(function(info, accept, deny) {\n  info.dstAddr = 'localhost';\n  accept();\n});\nsrv.listen(1080, 'localhost', function() {\n  console.log('SOCKS server listening on port 1080');\n});\n\nsrv.useAuth(socks.auth.None());\n```\n\n* Server with no authentication and denying all connections not made to port 80:\n\n```javascript\nvar socks = require('socksv5');\n\nvar srv = socks.createServer(function(info, accept, deny) {\n  if (info.dstPort === 80)\n    accept();\n  else\n    deny();\n});\nsrv.listen(1080, 'localhost', function() {\n  console.log('SOCKS server listening on port 1080');\n});\n\nsrv.useAuth(socks.auth.None());\n```\n\n* Server with no authentication, intercepting all connections to port 80, and passing through all others:\n\n```javascript\nvar socks = require('socksv5');\n\nvar srv = socks.createServer(function(info, accept, deny) {\n  if (info.dstPort === 80) {\n    var socket;\n    if (socket = accept(true)) {\n      var body = 'Hello ' + info.srcAddr + '!\\n\\nToday is: ' + (new Date());\n      socket.end([\n        'HTTP/1.1 200 OK',\n        'Connection: close',\n        'Content-Type: text/plain',\n        'Content-Length: ' + Buffer.byteLength(body),\n        '',\n        body\n      ].join('\\r\\n'));\n    }\n  } else\n    accept();\n});\nsrv.listen(1080, 'localhost', function() {\n  console.log('SOCKS server listening on port 1080');\n});\n\nsrv.useAuth(socks.auth.None());\n```\n\n* Client with no authentication:\n\n```javascript\nvar socks = require('socksv5');\n\nvar client = socks.connect({\n  host: 'google.com',\n  port: 80,\n  proxyHost: '127.0.0.1',\n  proxyPort: 1080,\n  auths: [ socks.auth.None() ]\n}, function(socket) {\n  console.log('\u003e\u003e Connection successful');\n  socket.write('GET /node.js/rules HTTP/1.0\\r\\n\\r\\n');\n  socket.pipe(process.stdout);\n});\n```\n\n* HTTP(s) client requests using a SOCKS Agent:\n\n```javascript\nvar socks = require('socksv5');\nvar http = require('http');\n\nvar socksConfig = {\n  proxyHost: 'localhost',\n  proxyPort: 1080,\n  auths: [ socks.auth.None() ]\n};\n\nhttp.get({\n  host: 'google.com',\n  port: 80,\n  method: 'HEAD',\n  path: '/',\n  agent: new socks.HttpAgent(socksConfig)\n}, function(res) {\n  res.resume();\n  console.log(res.statusCode, res.headers);\n});\n\n// and https too:\nvar https = require('https');\n\nhttps.get({\n  host: 'google.com',\n  port: 443,\n  method: 'HEAD',\n  path: '/',\n  agent: new socks.HttpsAgent(socksConfig)\n}, function(res) {\n  res.resume();\n  console.log(res.statusCode, res.headers);\n});\n```\n\n\nAPI\n===\n\nExports\n-------\n\n* **Server** - A class representing a SOCKS server.\n\n* **createServer**([\u003c _function_ \u003econnectionListener]) - _Server_ - Similar to `net.createServer()`.\n\n* **Client** - A class representing a SOCKS client.\n\n* **connect**(\u003c _object_ \u003eoptions[, \u003c _function_ \u003econnectListener]) - _Client_ - `options` must contain `port`, `proxyHost`, and `proxyPort`. If `host` is not provided, it defaults to 'localhost'.\n\n* **createConnection**(\u003c _object_ \u003eoptions[, \u003c _function_ \u003econnectListener]) - _Client_ - Aliased to `connect()`.\n\n* **auth** - An object containing built-in authentication handlers for Client and Server instances:\n\n    * **(Server usage)**\n\n        * **None**() - Returns an authentication handler that permits no authentication.\n\n        * **UserPassword**(\u003c _function_ \u003evalidateUser) - Returns an authentication handler that permits username/password authentication. `validateUser` is passed the username, password, and a callback that you call with a boolean indicating whether the username/password is valid.\n\n    * **(Client usage)**\n\n        * **None**() - Returns an authentication handler that uses no authentication.\n\n        * **UserPassword**(\u003c _string_ \u003eusername, \u003c _string_ \u003epassword) - Returns an authentication handler that uses username/password authentication.\n\n* **HttpAgent** - An Agent class you can use with `http.request()`/`http.get()`. Just pass in a configuration object like you would to the Client constructor or `connect()`.\n\n* **HttpsAgent** - Same as `HttpAgent` except it is for use with `https.request()`/`https.get()`.\n\n\nServer events\n-------------\n\nThese are the same as [net.Server](http://nodejs.org/docs/latest/api/net.html#net_class_net_server) events, with the following exception(s):\n\n* **connection**(\u003c _object_ \u003econnInfo, \u003c _function_ \u003eaccept, \u003c _function_ \u003edeny) - Emitted for each new (authenticated, if applicable) connection request. `connInfo` has the properties:\n\n    * **srcAddr** - _string_ - The remote IP address of the client that sent the request.\n\n    * **srcPort** - _integer_ - The remote port of the client that sent the request.\n\n    * **dstAddr** - _string_ - The destination address that the client has requested. This can be a hostname or an IP address.\n\n    * **dstPort** - _integer_ - The destination port that the client has requested.\n\n    `accept` has a boolean parameter which if set to `true`, will return the underlying `net.Socket` for you to read from/write to, allowing you to intercept the request instead of proxying the connection to its intended destination.\n\n\nServer methods\n--------------\n\nThese are the same as [net.Server](http://nodejs.org/docs/latest/api/net.html#net_class_net_server) methods, with the following exception(s):\n\n* **(constructor)**([\u003c _object_ \u003eoptions[, \u003c _function_ \u003econnectionListener]]) - Similar to `net.Server` constructor with the following extra `options` available:\n\n    * **auths** - _array_ - A pre-defined list of authentication handlers to use (instead of manually calling `useAuth()` multiple times).\n\n* **useAuth**(\u003c _function_ \u003eauthHandler) - _Server_ - Appends the `authHandler` to a list of authentication methods to allow for clients. This list's order is preserved and the first authentication method to match that of the client's list \"wins.\" Returns the Server instance for chaining.\n\n\nClient events\n-------------\n\n* **connect**(\u003c _Socket_ \u003econnection) - Emitted when handshaking/negotiation is complete and you are free to read from/write to the connected socket.\n\n* **error**(\u003c _Error_ \u003eerr) - Emitted when a parser, socket (during handshaking/negotiation), or DNS (if `localDNS` and `strictLocalDNS` are `true`) error occurs.\n\n* **close**(\u003c _boolean_ \u003ehad_error) - Emitted when the client is closed (due to error and/or socket closed).\n\n\nClient methods\n--------------\n\n* **(constructor)**(\u003c _object_ \u003econfig) - Returns a new Client instance using these possible `config` properties:\n\n    * **proxyHost** - _string_ - The address of the proxy to connect to (defaults to 'localhost').\n\n    * **proxyPort** - _integer_ - The port of the proxy to connect to (defaults to 1080).\n\n    * **localDNS** - _boolean_ - If `true`, the client will try to resolve the destination hostname locally. Otherwise, the client will always pass the destination hostname to the proxy server for resolving (defaults to true).\n\n    * **strictLocalDNS** - _boolean_ - If `true`, the client gives up if the destination hostname cannot be resolved locally. Otherwise, the client will continue and pass the destination hostname to the proxy server for resolving (defaults to true).\n\n    * **auths** - _array_ - A pre-defined list of authentication handlers to use (instead of manually calling `useAuth()` multiple times).\n\n* **connect**(\u003c _mixed_ \u003eoptions[, \u003c _function_ \u003econnectListener]) - _Client_ - Similar to `net.Socket.connect()`. Additionally, if `options` is an object, you can also set the same settings passed to the constructor.\n\n* **useAuth**(\u003c _function_ \u003eauthHandler) - _Server_ - Appends the `authHandler` to a list of authentication methods to allow for clients. This list's order is preserved and the first authentication method to match that of the client's list \"wins.\" Returns the Server instance for chaining.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmscdex%2Fsocksv5","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmscdex%2Fsocksv5","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmscdex%2Fsocksv5/lists"}