Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TCP socket client through proxy on nodejs

I need to make tcp socket connection to smtp server. Is it possible to connect through proxy server on nodejs? Is there any npm modules available to use? I couldn't find any at all.

var net = require('net');

var HOST = '127.0.0.1';
var PORT = 6969;

var client = new net.Socket();
client.connect(PORT, HOST, function() {
    console.log('CONNECTED TO: ' + HOST + ':' + PORT);
    client.write('I am here!');
});

// Add a 'data' event handler for the client socket
// data is what the server sent to this socket
client.on('data', function(data) {

    console.log('DATA: ' + data);

});

// Add a 'close' event handler for the client socket
client.on('close', function() {
    console.log('Connection closed');
});
like image 277
Chamnap Avatar asked Nov 21 '22 23:11

Chamnap


1 Answers

net.socket, tls.connect and dgram have no proxy support.

The simplest way to use it with proxy is to replace some libc functions with proxychains or something similar.

var client = require('tls')
.connect(443, 'www.facebook.com', function() {
  console.log('connected');
  client.write('hello');
})
.on('data', function(data) {
  console.log('received', data.toString());
})
.on('close', function() {
  console.log('closed');
});

proxychains node fit.js

connected
received HTTP/1.1 400 Bad Request
...
closed
like image 127
puchu Avatar answered Dec 10 '22 08:12

puchu