mattcg / socks5-http-client Goto Github PK
View Code? Open in Web Editor NEWSOCKS v5 HTTP client implementation in JavaScript for Node.js.
SOCKS v5 HTTP client implementation in JavaScript for Node.js.
Could you please publish an update of this package to NPM with the socks5-client dependency updated?
Reading #15 I'm guessing that it would fix:
Error: SOCKS authentication failed. Unexpected SOCKS authentication method: 255.
Currently the npm package installs [email protected]
which I believe is causing the error.
the socks5 agent work well with some public socks5 servers, but may failed with some else.
1 I confirmed the socks5 server is ok, i checked it buy using it on chrome and socks lib(another lib)
2 my core test code is like this
request.get(url, { agentClass: Agent, agentOptions: { socksHost:proxy.ip, socksPort:proxy.port } });
3 the error log is long, like this:
proxy: Proxy { ip: '122.192.32.79', port: 1080, protocol: 'socks5' } test failed: { RequestError: Error: connect ETIMEDOUT 122.192.32.79:1080 at new RequestError (h:\workspace\jdmsk\node_modules\request-promise-core\lib\errors.js:14:15) at Request.module.exports.plumbing.callback (h:\workspace\jdmsk\node_modules\request-promise-core\lib\plumbing.js:87:29) at Request.RP$callback [as _callback] (h:\workspace\jdmsk\node_modules\request-promise-core\lib\plumbing.js:46:31) at Request.init.self.callback (h:\workspace\jdmsk\node_modules\request\request.js:186:22) at emitOne (events.js:96:13) at Request.emit (events.js:188:7) at Request.onRequestError (h:\workspace\jdmsk\node_modules\request\request.js:845:8) at emitOne (events.js:96:13) at ClientRequest.emit (events.js:188:7) at Socks5ClientSocket.socketErrorListener (_http_client.js:309:9) at emitOne (events.js:101:20) at Socks5ClientSocket.emit (events.js:188:7) at Socket.<anonymous> (h:\workspace\jdmsk\node_modules\socks5-client\lib\Socket.js:39:8) at emitOne (events.js:96:13) at Socket.emit (events.js:188:7) at emitErrorNT (net.js:1281:8) at _combinedTickCallback (internal/process/next_tick.js:74:11) at process._tickCallback (internal/process/next_tick.js:98:9) name: 'RequestError', message: 'Error: connect ETIMEDOUT 122.192.32.79:1080', cause: { Error: connect ETIMEDOUT 122.192.32.79:1080 at Object.exports._errnoException (util.js:1022:11) at exports._exceptionWithHostPort (util.js:1045:20) at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1090:14) code: 'ETIMEDOUT', errno: 'ETIMEDOUT', syscall: 'connect', address: '122.192.32.79', port: 1080 }, error: { Error: connect ETIMEDOUT 122.192.32.79:1080 at Object.exports._errnoException (util.js:1022:11) at exports._exceptionWithHostPort (util.js:1045:20) at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1090:14) code: 'ETIMEDOUT', errno: 'ETIMEDOUT', syscall: 'connect', address: '122.192.32.79', port: 1080 }, options: { agentClass: { [Function: Agent] super_: [Object] }, agentOptions: { socksHost: '122.192.32.79', socksPort: 1080 }, uri: 'http://www.ownchip.cn/myip.php', method: 'GET', callback: [Function: RP$callback], transform: undefined, simple: true, resolveWithFullResponse: false, transform2xxOnly: false }, response: undefined }
the servers i found not work with this lib are : 122.192.32.76:7280, 61.238.32.69:1080, 122.192.32.79:7280
they are public servers, maybe unavailable some time.
I think that one of your dependencies (socks5-client) has some issues with the latest stable version of node.
With node 5 I get the following error (that I don't get with the previous versions of node):
_http_outgoing.js:657
socket.cork();
^
TypeError: socket.cork is not a function
at ClientRequest._flushOutput (_http_outgoing.js:657:10)
at ClientRequest.OutgoingMessage._flush (_http_outgoing.js:636:16)
at _http_client.js:154:10
at Socks5ClientSocket.callSocketMethod (_http_client.js:519:7)
at Socks5ClientSocket.g (events.js:260:16)
at emitNone (events.js:67:13)
at Socks5ClientSocket.emit (events.js:166:7)
at Socks5ClientSocket.handleSocksConnectToHost (/Users/xxxxx/Projects/xxxxx/node_modules/socks5-client/lib/Socks5ClientSocket.js:133:7)
at /Users/xxxxx/Projects/xxxxx/node_modules/socks5-client/lib/Socks5ClientSocket.js:141:9
at Socket.<anonymous> (/Users/xxxxx/Projects/xxxxx/node_modules/socks5-client/lib/Socks5ClientSocket.js:224:4)
Hello,
The readme says:
Specify the
socksHost
andsocksPort
options if your SOCKS server isn't running onlocalhost:1080
However, it doesn't tell how to set options, in the use()
usage.
How is this done, and is there a reason this should be kept out of the readme?
How to integrate with this module https://github.com/mikeal/request to make request through Tor?
if I dont set proxy options
it will use 127.0.0.1:1080
anyway there is no proxy
How to use more than 1 proxy?
for example I want do 1 reuest and next time i want to do request with other proxy?
It receive no messages from socks without error messages.
Trying to connect to a web socket with a proxy agent (tor)
Using ubuntu 18
Node v8.16.1
The message is sent to the endpoit at ngrok.io, but the application crashes right after.
Code:
const Agent = require("socks5-http-client/lib/Agent"); // Constructor
let agent = new Agent({
socksHost: 'localhost', // Defaults to 'localhost'.
socksPort: 9050 // Defaults to 1080.
});
var socket = require('socket.io-client').connect('http://38d7b774.ngrok.io', { agent: agent });
socket.on('connect', function() {
socket.emit('send', 'random');
});
Error:
_http_client.js:486
socket._readableState.flowing = null;
^
TypeError: Cannot set property 'flowing' of undefined
at Socks5ClientSocket.socketOnData (_http_client.js:486:37)
at emitOne (events.js:116:13)
at Socks5ClientSocket.emit (events.js:211:7)
at Socket.<anonymous> (/home/caramori/Documents/Jera/Node/trk-core/node_modules/socks5-client/lib/Socket.js:150:8)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
at readableAddChunk (_stream_readable.js:250:11)
at Socket.Readable.push (_stream_readable.js:208:10)
at TCP.onread (net.js:601:20)
Hi,
When using node version 14.17.0 or above, it gives a ECONNREFUSED
error.
[client] [HPM] Error occurred while proxying request localhost:3000/api/test_api to http://localhost:5001/ [ECONNREFUSED] (https://nodejs.org/api/errors.html#errors_common_system_errors)
The server gives 302 redirects but the client is not following them.
Is there a workaround?
Hey,
I am facing some issue with the module.
vents.js:85
throw er; // Unhandled 'error' event
^
Error: connect ECONNREFUSED
at exports._errnoException (util.js:746:11)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1010:19)
I am not sure how to proxy requests from nodejs to tor. I have tor running on my ubuntu and the browser running too with the tor-browser-en.sh
I am not sure about what options I need to pass into the requst
require('socks5-https-client').request({
'url': url,
strictSSL: true,
agentClass: Agent,
agentOptions: {
// socksHost: 'my-tor-proxy-host', // Defaults to 'localhost'.
socksPort: 9050 // Defaults to 1080.
}
}, function (error, response, body) {
//something
});
Please help. Thanks!
PS: I faced the same issue with https module
mattcg/socks5-https-client#10
I'm having problem with setTimeout. It doesn't execute at all.
var conn = SocksProxy.get(options,function ( response ) {
...
})
conn.setTimeout(5000)
conn.on('timeout', function(){
...
})
I also tried conn.setTimeout(5000, function(){ ... })
but that didn't work either.
Hey, I tried to use the Agent in combination with request and changing tor proxy hostnames. One Tor is running on localhost, the other on 'tor_proxy'.
request(
{
uri: 'http://ipv4bot.whatismyipaddress.com',
agentClass: Agent,
agentOptions: {
socksHost: 'localhost',
socksPort: Tor.PORT
}
}, function (error, response, body) {
console.log(body);
});
works as expected, the request is running over the localhost tor. The second request however
request(
{
uri: 'http://ipv4bot.whatismyipaddress.com',
agentClass: Agent,
agentOptions: {
socksHost: 'tor_proxy',
socksPort: Tor.PORT
}
}, function (error, response, body) {
console.log(body);
});
Is also running over localhost. I investigated a bit further, and looking at which options are coming into socks5-http-client/lib/Agent, the first one is
Url {
protocol: 'http:',
slashes: true,
auth: null,
host: 'ipv4bot.whatismyipaddress.com',
port: 80,
hostname: 'ipv4bot.whatismyipaddress.com',
hash: null,
search: null,
query: null,
pathname: '/',
path: '/',
href: 'http://ipv4bot.whatismyipaddress.com/',
socksPort: 9050,
socksHost: 'localhost' }
and the second one
Url {
protocol: 'http:',
slashes: true,
auth: null,
host: 'ipv4bot.whatismyipaddress.com',
port: 80,
hostname: 'ipv4bot.whatismyipaddress.com',
hash: null,
search: null,
query: null,
pathname: '/',
path: '/',
href: 'http://ipv4bot.whatismyipaddress.com/',
socksPort: 9050,
socksHost: 'tor_proxy',
agent:
Agent {
domain: null,
_events: { free: [Function] },
_eventsCount: 1,
_maxListeners: undefined,
defaultPort: 80,
protocol: 'http:',
options:
{ socksHost: 'localhost',
socksPort: 9050,
href: 'http://ipv4bot.whatismyipaddress.com/',
path: null,
pathname: '/',
query: null,
search: null,
hash: null,
hostname: 'ipv4bot.whatismyipaddress.com',
port: 80,
host: 'ipv4bot.whatismyipaddress.com',
auth: null,
slashes: true,
protocol: 'http:' },
requests: {},
sockets: {},
freeSockets: {},
keepAliveMsecs: 1000,
keepAlive: false,
maxSockets: Infinity,
maxFreeSockets: 256,
socksHost: 'localhost',
socksPort: 9050,
createConnection: [Function] } `}
Seems like request is caching the agent if it used one before and so not changing the proxy hostname.
I'm not sure if this goes here, but I'm using the library to connect through tor and I'm only getting the first chunk of the response. Do you know anything about this issue?
Hi, as I've pointed out at #24 (comment), the merged PR is not shipped yet. As the current version introduces unnecessary dependencies as well as npm audit reports, It will be of great help if the package on npm could be updated.
This is my code:
var request = require('request');
module.exports = function () {
var config_data = config.proxy();
if (config_data) {
switch (config_data['type']) {
case 'http':
var url = 'http://' + config_data['proxy'].host + ':' + config_data['proxy'].port;
return request.defaults({'proxy': url});
case 'socks':
var Socks5ClientHttpAgent = require('socks5-http-client/lib/agent');
var options = {
'socksHost':config_data['proxy']['host'],
'socksPort':config_data['proxy']['port']
};
var socks5Proxy = new Socks5ClientHttpAgent(options);
return request.defaults({'agent': socks5Proxy});
default:
return request;
}
} else {
return request;
}
};
you can repuduece it as follows:
how use username and password
So this is the error i get when trying to run the tor example with node v4.2.1:
_http_outgoing.js:642
socket.cork();
^
TypeError: socket.cork is not a function
at ClientRequest.OutgoingMessage._flush (_http_outgoing.js:642:14)
at _http_client.js:148:10
at Socks5ClientSocket.callSocketMethod (_http_client.js:513:7)
at Socks5ClientSocket.g (events.js:260:16)
at emitNone (events.js:67:13)
at Socks5ClientSocket.emit (events.js:166:7)
at Socks5ClientSocket.handleSocksConnectToHost (/Users/cocoon/project/coding/bgg/node_modules/socks5-client/lib/Socket.js:133:7)
at TLSSocket.<anonymous> (/Users/cocoon/project/coding/bgg/node_modules/socks5-https-client/lib/Agent.js:32:29)
at TLSSocket.g (events.js:260:16)
at emitNone (events.js:67:13)
at TLSSocket.emit (events.js:166:7)
at TLSSocket.<anonymous> (_tls_wrap.js:1021:14)
at emitNone (events.js:67:13)
at TLSSocket.emit (events.js:166:7)
at TLSSocket._finishInit (_tls_wrap.js:567:8)
npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
I don't know what happens, but could you run test with scenario high traffic?
Because my server hang and can't restart with PM2. If that is happens with node 0.12.0, I switch to 0.10.34 or 0.10.36, it is still causes hang.. Thanks
ps: the complete indication of my server hang is the first post, FYI:
Unitech/pm2#1072
I'm getting the following error while making more than 5 subsequent request to locally run socks server on port 1080.
Error: socket hang up
at createHangUpError (_http_client.js:252:15)
at Socks5ClientSocket.socketOnEnd (_http_client.js:344:23)
at emitNone (events.js:86:13)
at Socks5ClientSocket.emit (events.js:185:7)
at Socket.<anonymous> (/home/xyz/exp/socksv5-client/node_modules/socks5-client/lib/Socket.js:129:8)
at emitNone (events.js:91:20)
at Socket.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:934:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9) code: 'ECONNRESET' }
When POST returns 301, the following GET isn't using the same agent setting.
var options = {
url: 'http://website/',
method: 'POST',
headers: headers,
followAllRedirects: true,
agent: new Socks5ClientHttpAgent({socksHost: '127.0.0.1', socksPort: 9050}),
form: {
...
}
}
// POST returns 301 /index.php
request.post(options, function (err, httpResponse, body) {...});
With this example POST goes through TOR but the following GET doesn't.
I got this:
Error: SOCKS connection failed. Connection refused.
at Socket.socket.ondata (/home/apps/test/node_modules/socks5-http-client/node_modules/socks5-client/lib/socket.js:193:12)
at TCP.onread (net.js:527:27)
what is that?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.