Giter VIP home page Giter VIP logo

check-proxy's Introduction

Build Status

Check-proxy - Advanced Node proxy testing library

This is an advanced proxy checking library. Requires curl.

What it does:

  • checks http, socks4 and socks5 proxies
  • performs actual requests, not just pings
  • checks GET, POST, COOKIES, referer support
  • checks https support
  • checks country
  • checks proxy speed - provides total time and connect time
  • checks anonymity (binary checks - anonymous or not, 1 - anonymous, i.e. doesn't leak your IP address in any of the headers, 0 - not anonymous)
  • checks if proxy supports particular websites - by custom function, regex or substring search
  • allows to set connect timeout and overall timeout

It will return a promise that is either fulfilled with array of working proxies and protocols (some proxies support SOCKS4/SOCKS5 on the same port) or rejected if it wasn't able to connect on provided port.

Installation

  npm install check-proxy --save

Usage

Library consists of two parts - client and server. This allows to reliably check proxy parameters like GET, POST, COOKIES support. See example directory for OpenShift server app. Websites are checked against specified function, regex or string.

//client.js
var checkProxy = require('check-proxy').check;
checkProxy({
  testHost: 'ping.rhcloud.com', // put your ping server url here
  proxyIP: '107.151.152.218', // proxy ip to test
  proxyPort: 80, // proxy port to test
  localIP: '185.103.27.23', // local machine IP address to test
  connectTimeout: 6, // curl connect timeout, sec
  timeout: 10, // curl timeout, sec
  websites: [
    {
      name: 'example',
      url: 'http://www.example.com/',
      regex: /example/gim, // expected result - regex

    },
    {
      name: 'yandex',
      url: 'http://www.yandex.ru/',
      regex: /yandex/gim, // expected result - regex

    },
    {
      name: 'google',
      url: 'http://www.google.com/',
      regex: function(html) { // expected result - custom function
        return html && html.indexOf('google') != -1;
      },
    },
    {
      name: 'amazon',
      url: 'http://www.amazon.com/',
      regex: 'Amazon', // expected result - look for this string in the output
    },

  ]
}).then(function(res) {
	console.log('final result', res);
}, function(err) {
  console.log('proxy rejected', err);
});
//result
/*
[{
  get: true,
  post: true,
  cookies: true,
  referer: true,
  'user-agent': true,
  anonymityLevel: 1,
  supportsHttps: true,
  protocol: 'http',
  ip: '107.151.152.218',
  port: '80',
  country: 'MX',
  connectTime: 0.23, // Time in seconds it took to establish the connection
  totalTime: 1.1, // Total transaction time in seconds for last the transfer
  websites: {
    example: true,
    google: true,
    amazon: true,
    yandex: false
  }
}]
*/
//server.js
var express = require('express'),
    app = express(),
    url = require('url'),
    bodyParser = require('body-parser'),
    cookieParser = require('cookie-parser'),
    getProxyType = require('check-proxy').ping;

app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(cookieParser());

var ping = function(req, res) {
  console.log('ip', req.connection.remoteAddress);
  console.log('headers', req.headers);
	console.log('cookies', req.cookies);
  res.json(getProxyType(req.headers, req.query, req.body, req.cookies));
}

app.get('/', ping);
app.post('/', ping);

var ipaddress = process.env.OPENSHIFT_NODEJS_IP;
var port = process.env.OPENSHIFT_NODEJS_PORT || 8080;

if (typeof ipaddress === "undefined") {
    //  Log errors on OpenShift but continue w/ 127.0.0.1 - this
    //  allows us to run/test the app locally.
    console.warn('No OPENSHIFT_NODEJS_IP var, using 127.0.0.1');
    ipaddress = "127.0.0.1";
};

app.listen(port, ipaddress, function() {
  console.log('%s: Node server started on %s:%d ...',
              Date(Date.now() ), ipaddress, port);
});

Tests

npm test

Release History

  • 0.0.3 Initial release

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.