How to use the socks.SocksClient.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 ssbc / multiserver / plugins / onion.js View on Github external
server: function (onConnection, cb) {
      if(!opts.server) return

      var serverOpts = {
        proxy: proxyOpts,
        command: "bind",
        destination: {
          host: opts.host,
          port: opts.port
        }
      }
      var controlSocket = null
      socks.createConnection(serverOpts, function (err, socket) {
        if(err) {
          console.error('unable to find local tor server.')
          console.error('will be able receive tor connections') // << ???
          return
        }
        controlSocket = socket

        socket.on('data', function(stream) {
          stream = toPull.duplex(stream)
          stream.address = 'onion:'
          onConnection(stream)
          
        })

        cb(null, true);
github TooTallNate / node-socks-proxy-agent / src / agent.ts View on Github external
if (!host) {
			throw new Error('No `host` defined!');
		}

		if (lookup) {
			// Client-side DNS resolution for "4" and "5" socks proxy versions.
			host = await dnsLookup(host);
		}

		const socksOpts: SocksClientOptions = {
			proxy,
			destination: { host, port },
			command: 'connect'
		};
		debug('Creating socks proxy connection: %o', socksOpts);
		const { socket } = await SocksClient.createConnection(socksOpts);
		debug('Successfully created socks proxy connection');

		if (opts.secureEndpoint) {
			const servername = opts.servername || opts.host;
			if (!servername) {
				throw new Error('Could not determine "servername"');
			}
			// The proxy is connecting to a TLS server, so upgrade
			// this socket connection to a TLS connection.
			debug('Upgrading socket connection to TLS');
			return tls.connect({
				...omit(opts, 'host', 'hostname', 'path', 'port'),
				socket,
				servername
			});
		}
github electerm / electerm / app / server / socks.js View on Github external
timeout: readyTimeout
      }
      request(opts)
        .on('error', (e) => {
          console.error(`fail to connect proxy: ${e.message}`)
          reject(e)
        })
        .on('connect', (res, socket) => {
          resolve({ socket: socket })
        })
        .end()
    })
  }

  // use socks proxy
  return SocksClient.createConnection(options)
}
github ssbc / multiserver / plugins / onion.js View on Github external
client: function (opts, cb) {
      var started = false, _socket, destroy

      var connectOpts = {
        proxy: proxyOpts,
        command: "connect",
        destination: {
          host: opts.host,
          port: opts.port
        }
      }

      socks.createConnection(connectOpts, function(err, result) {
        if (err) return cb(err)

        var socket = result.socket

        if(destroy) return socket.destroy()
        _socket = socket

        var duplexStream = toPull.duplex(socket)
        duplexStream.address = 'onion:'+connectOpts.destination.host+':'+connectOpts.destination.port

        cb(null, duplexStream)

        // Remember to resume the socket stream.
        socket.resume()
      })
      return function () {
github thomas-crane / nrelay / src / core / client.ts View on Github external
}
    if (this.frameUpdateTimer) {
      clearInterval(this.frameUpdateTimer);
      this.frameUpdateTimer = null;
    }
    if (this.projectiles.length > 0) {
      this.projectiles = [];
    }
    if (this.projectileUpdateTimer) {
      clearInterval(this.projectileUpdateTimer);
      this.projectileUpdateTimer = null;
    }

    if (this.proxy) {
      Logger.log(this.alias, 'Establishing proxy', LogLevel.Info);
      SocksClient.createConnection({
        proxy: {
          ipaddress: this.proxy.host,
          port: this.proxy.port,
          type: this.proxy.type,
          userId: this.proxy.userId,
          password: this.proxy.password
        },
        command: 'connect',
        destination: {
          host: this.internalServer.address,
          port: 2050
        }
      }).then((info) => {
        Logger.log(this.alias, 'Established proxy!', LogLevel.Success);
        this.clientSocket = info.socket;
        this.initSocket(false);

socks

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

MIT
Latest version published 9 days ago

Package Health Score

83 / 100
Full package analysis