How to use the socks.createConnection function in socks

To help you get started, we’ve selected a few socks examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nodemailer / nodemailer / examples / proxy / custom-proxy.js View on Github external
transporter.getSocket = function (options, callback) {
    console.log('Socket requested to %s:%s', options.host, options.port);

    var proxyOptions = {
        proxy: proxy,
        target: {
            host: options.host,
            port: options.port
        },
        command: 'connect'
    };

    console.log(proxyOptions);
    Socks.createConnection(proxyOptions, function(err, socket){
        callback(err, {
            // everything we pass here will be appended to the options of smtp-connection
            // see possible options here:
            // https://github.com/nodemailer/smtp-connection#create-smtpconnection-instance
            connection: socket,
            tls: {
                rejectUnauthorized: true
            }
        });
    });
};
github asluchevskiy / http-to-socks-proxy / lib / proxy-server.js View on Github external
resolve(ph.hostname, function (err, hostname) {
            if (err) {
                console.error('Resolve error for domain ' + ph.hostname + ': ' + err.message);
                socketRequest.write('HTTP/' + request.httpVersion + ' 105 Name Not Resolved\r\n\r\n');
                socketRequest.end();
                return;
            }
            var options = {
                proxy: proxy,
                //target: {host: ph.hostname, port: ph.port},
                target: {host: hostname, port: ph.port},
                command: 'connect'
            };
            Socks.createConnection(options, function (err, socket, info) {
                if (err) {
                    // error in SocksSocket creation
                    console.error(err.message + ' connection creating on ' + proxy.ipaddress + ':' + proxy.port);
                    socketRequest.write('HTTP/' + request.httpVersion + ' 500 Connection error\r\n\r\n');
                    return;
                }
                // tunneling to the host
                socket.on('data', function (chunk) { socketRequest.write(chunk) });
                socket.on('end', function () { socketRequest.end() });
                socket.on('error', function (err) {
                    // error in transfer
                    console.error(err.message + ' on proxy ' + proxy.ipaddress + ':' + proxy.port);
                    socketRequest.write('HTTP/' + request.httpVersion + ' 500 Connection error\r\n\r\n');
                    socketRequest.end();
                });
                // tunneling to the client
github dodrio / jet / lib / proxy-server.js View on Github external
proxySocket.write(head)

      proxySocket.pipe(socket)
      socket.pipe(proxySocket)
    })

    proxySocket.on('error', () => {
      socket.write(headerError(request.httpVersion))
    })
  } else {
    const options = {
      proxy,
      target: { host, port }
    }

    Socks.createConnection(options, (err, proxySocket) => {
      if (err) {
        return socket.write(headerError(request.httpVersion))
      }

      // tell the client that the connection is established
      socket.write(headerEstablished(request.httpVersion))
      proxySocket.write(head)

      // creating pipes in both ends
      proxySocket.pipe(socket)
      socket.pipe(proxySocket)
    })
  }
}
github oyyd / http-proxy-to-socks / src / proxy_server.js View on Github external
const options = {
    proxy,
    target: { host, port },
    command: 'connect',
  };

  let socket;

  socketRequest.on('error', (err) => {
    logger.error(`${err.message}`);
    if (socket) {
      socket.destroy(err);
    }
  });

  Socks.createConnection(options, (error, _socket) => {
    socket = _socket;

    if (error) {
      // error in SocksSocket creation
      logger.error(`${error.message} connection creating on ${proxy.ipaddress}:${proxy.port}`);
      socketRequest.write(`HTTP/${request.httpVersion} 500 Connection error\r\n\r\n`);
      return;
    }

    socket.on('error', (err) => {
      logger.error(`${err.message}`);
      socketRequest.destroy(err);
    });

    // tunneling to the host
    socket.pipe(socketRequest);
github dodrio / jet / lib / agent.js View on Github external
const _socket = net.connect(port, hostname, () => {
      // tell the client that the connection is established
      socket.write(jetHeader(req.httpVersion))
      _socket.write(head)
      // creating pipes in both ends
      _socket.pipe(socket)
      socket.pipe(_socket)
    })

    _socket.on('error', (err) => {
      return next(err)
    })
  } else {
    logger.request(req, 'tunnel')

    Socks.createConnection({
      proxy,
      target: {
        host: hostname,
        port: port
      },
      command: 'connect'
    }, (err, _socket, info) => {
      if (err) {
        return next(err)
      } else {
        // tell the client that the connection is established
        socket.write(jetHeader(req.httpVersion))
        _socket.write(head)
        // creating pipes in both ends
        _socket.pipe(socket)
        socket.pipe(_socket)
github UnsignedInt8 / LightSword / test / socks5.ts View on Github external
it('status test', async (done) => {
    socks.createConnection(clientOpts, async (err, socket, info) => {
      if (err) return assert.fail(err, null, err.message);
      assert(net.isIP(socket.remoteAddress));
      done();
    });
  });
});
github jin5354 / gbfplayer / js / services / proxy.js View on Github external
};

            if(config.agentType == '1') {
                let socksOptions = {
                    proxy: {
                        ipaddress: config.agentHost,
                        port: config.agentPort,
                        type: 5
                    },
                    target: {
                        host: requestOptions.host,  
                        port: requestOptions.port
                    }
                };

                Socks.createConnection(socksOptions, function(err, tunnel, info) {
                    if (err)
                        console.log(err);
                    else {
                        
                        _synReply(socket, 200, 'Connection established', {
                            'Connection': 'keep-alive'
                        },
                        function(error) {
                            if (error) {
                                console.log(`syn error: ${error.message}`);
                                tunnel.end();
                                socket.end();
                                return;
                            }
                            tunnel.resume();
                            tunnel.pipe(socket);

socks

Fully featured SOCKS proxy client supporting SOCKSv4, SOCKSv4a, and SOCKSv5. Includes Bind and Associate functionality.

MIT
Latest version published 8 months ago

Package Health Score

76 / 100
Full package analysis