How to use the socks.Agent 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 shangxinbo / cardinal / bin / app.js View on Github external
function optimal() {
    let httpRunning = false             // to prevent mutiple http create
    if (socksPorts.length <= 0) {
        init()
        return false
    }
    for (let i = 0; i < socksPorts.length; i++) {
        let tmp = socksPorts[i]
        let req = http.get({
            hostname: 'google.com',
            port: 80,
            agent: new socks.Agent({
                proxy: {
                    ipaddress: config.host,
                    port: socksPorts[i],
                    type: 5
                }
            }, false, false)
        }, (res) => {
            if (res.statusCode == 200 || res.statusCode == 302) {
                if (!httpRunning) {
                    start(tmp)
                    if (updateIPs) {
                        pac.updateIPs(tmp)
                    }
                    httpRunning = true
                }
            }
github asluchevskiy / http-to-socks-proxy / lib / proxy-server.js View on Github external
resolve(ph.host, function(err, hostname) {
            if (err) {
                console.error('Resolve error for domain ' + ph.hostname + ': ' + err.message);
                response.writeHead(105);
                response.end('Name Not Resolved');
            } else {
                var socksAgent = new Socks.Agent({
                    proxy: proxy,
                    target: {host: hostname, port: ph.port}
                });
                var options = {
                    port: ph.port,
                    hostname: ph.hostname,
                    method: request.method,
                    path: ph.path,
                    headers: request.headers,
                    agent: socksAgent
                };
                var proxyRequest = http.request(options);
                proxyRequest.setTimeout(10000, function() {
                    response.writeHead(504);
                    response.end('Gateway Timeout\n');
                    if (proxyRequest.socket)
github dodrio / jet / lib / proxy-server.js View on Github external
function requestListener (request, response) {
  const { direct, hostname, port, path } = request.urlObj

  const method = request.method
  const headers = request.headers
  const agent = new Socks.Agent({ proxy }, false, false)

  const options = {
    hostname,
    port,
    path,
    method,
    headers
  }

  if (!direct) {
    options.agent = agent
  }

  const proxyRequest = http.request(options)

  proxyRequest.on('response', proxyResponse => {
github shangxinbo / cardinal / http / agent.js View on Github external
const method = req.method
        const headers = req.headers

        const options = {
            hostname,
            port,
            path,
            method,
            headers
        }

        if (direct) {
            logger.request(req, 'direct')
        } else {
            logger.request(req, 'tunnel')
            options.agent = new Socks.Agent({proxy}, false, false)
        }

        const jetRequest = http.request(options, (_res) => {
            _res.pipe(res)
            res.writeHead(_res.statusCode, _res.headers)
        })

        jetRequest.on('error', (err) => {
            logger.error(err)
        })
        req.pipe(jetRequest)
    }
}
github dodrio / jet / lib / agent.js View on Github external
const method = req.method
  const headers = req.headers

  const options = {
    hostname,
    port,
    path,
    method,
    headers
  }

  if (direct) {
    logger.request(req, 'direct')
  } else {
    logger.request(req, 'tunnel')
    options.agent = new Socks.Agent({ proxy }, false, false)
  }

  const _req = http.request(options, (_res) => {
    res.writeHead(_res.statusCode, _res.headers)
    _res.pipe(res)
  })

  _req.on('error', (err) => {
    return next(err)
  })

  _req.end()
}
github shangxinbo / cardinal / pac / index.js View on Github external
exports.updateIPs = function (port) {
    let req = http.get({
        hostname: 'www.ipdeny.com',
        port: 80,
        path: '/ipblocks/data/aggregated/cn-aggregated.zone',
        agent: new socks.Agent({
            proxy: {
                ipaddress: config.host,
                port: port,
                type: 5
            }
        }, false, false)
    }, function (res) {
        if (res.statusCode == 200 || res.statusCode == 302) {
            res.setEncoding('utf-8')
            let allIps = ''
            res.on('data', function (chunk) {
                allIps += chunk
            }).on('end', function () {
                fs.writeFile(path.join(__dirname, '../config/GeoIP-CN'), allIps)
            })
        }
github shangxinbo / cardinal / http / agent.js View on Github external
return function (req, res) {
        const _url = url.parse(req.url)

        let options = {
            hostname: _url.hostname,
            port: _url.port,
            path: _url.path,
            method: _url.method,
            headers: req.headers
        }

        options.agent = new Socks.Agent({
            proxy: {
                ipaddress: host,
                port: sockPort,
                type: 5
            }
        }, false, false)

        const _req = http.request(options, (_res) => {
            res.writeHead(_res.statusCode, _res.headers)
            _res.pipe(res)
        }).on('error', (err) => {
            logger.error(`Agent http ${err}`)
            if (callback) callback()
            res.end()
        })
        req.pipe(_req)
github oyyd / http-proxy-to-socks / src / proxy_server.js View on Github external
function requestListener(getProxyInfo, request, response) {
  logger.info(`request: ${request.url}`);

  const proxy = getProxyInfo();
  const ph = url.parse(request.url);

  const socksAgent = new Socks.Agent({
    proxy,
    target: { host: ph.hostname, port: ph.port },
  });

  const options = {
    port: ph.port,
    hostname: ph.hostname,
    method: request.method,
    path: ph.path,
    headers: request.headers,
    agent: socksAgent,
  };

  const proxyRequest = http.request(options);

  request.on('error', (err) => {

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