You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP

nodejs-proxy-checkerv2

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nodejs-proxy-checkerv2 - npm Package Compare versions

Comparing version

to
1.2.0

@@ -10,2 +10,4 @@ import ProxyAnonymousLevel from "../enum/ProxyAnonymousLevel";

port: string;
username: string;
password: string;
proxyJudgeSelected: string;

@@ -23,12 +25,17 @@ proxyInformationProviderSelected: string;

checkProxy(proxyJudgeSelected: string, proxyInformationProviderSelected: string, myIP: string, timeout?: number): Promise<void>;
private checkWithHttpProxy;
private checkWithSockProxy;
private handleCalculProxySpeed;
private setAnonymousInformation;
private getProxyJudgeInformation;
private getProxyInformation;
/**
* Parse data of proxy judege to object with key:value
* @param {string} content proxy judge response
* @returns {object}
*/
* Parse data of proxy judege to object with key:value
* @param {string} content proxy judge response
* @returns {object}
*/
private parseProxyJudgeInformation;
private generateAxiosHandler;
private generateHttpAxiosHandler;
private generateSocksAxiosHandler;
}
export default Proxy;

@@ -20,10 +20,15 @@ "use strict";

const performance_1 = require("../helpers/performance");
const splitter_1 = require("../helpers/splitter");
const socks_proxy_agent_1 = require("socks-proxy-agent");
const request_1 = require("../helpers/request");
class Proxy {
constructor(proxy, axios) {
this.username = "";
this.password = "";
this.proxyJudgeSelected = "";
this.proxyInformationProviderSelected = "";
this.anonymousLevel = ProxyAnonymousLevel_1.default.Unknwow;
this.speedLevel = ProxySpeedLevel_1.default.Unknwow;
this.status = ProxyStatus_1.default.Unknwow;
this.version = ProxyVersion_1.default.Unknwow;
this.anonymousLevel = ProxyAnonymousLevel_1.default.Unknown;
this.speedLevel = ProxySpeedLevel_1.default.Unknown;
this.status = ProxyStatus_1.default.Unknown;
this.version = ProxyVersion_1.default.Unknown;
this.timeTaken = 0;

@@ -35,4 +40,9 @@ this.country = "";

this.axios = axios;
this.address = proxy.split(':')[0];
this.port = proxy.split(':')[1];
const { values, hasAuth } = splitter_1.proxySplit(proxy);
this.address = values[0];
this.port = values[1];
if (hasAuth) {
this.username = values[2];
this.password = values[3];
}
}

@@ -44,10 +54,30 @@ checkProxy(proxyJudgeSelected, proxyInformationProviderSelected, myIP, timeout = 0) {

this.timeout = timeout;
let data;
var start = performance_1.clock(null);
yield this.checkWithHttpProxy();
var end = performance_1.clock(start);
if (this.status === ProxyStatus_1.default.Dead) {
var start = performance_1.clock(null);
yield this.checkWithSockProxy();
}
var end = performance_1.clock(start);
if (this.status === ProxyStatus_1.default.Dead)
return;
if (typeof end === "number") {
this.timeTaken = end;
this.handleCalculProxySpeed();
}
if (proxyJudgeSelected) {
const dataProxyJudge = yield this.getProxyJudgeInformation();
this.setAnonymousInformation(dataProxyJudge, myIP);
}
if (proxyInformationProviderSelected) {
yield this.getProxyInformation();
}
});
}
checkWithHttpProxy() {
return __awaiter(this, void 0, void 0, function* () {
try {
var start = performance_1.clock(null);
const result = yield this.generateAxiosHandler(proxyJudgeSelected);
var end = performance_1.clock(start);
if (typeof end === "number")
this.timeTaken = end;
if (result.status !== 200) {
const resultWithHttp = yield this.generateHttpAxiosHandler("http://check-host.net/ip");
if (!request_1.checkRequestResponseIsGood(resultWithHttp.status)) {
this.status = ProxyStatus_1.default.Dead;

@@ -57,3 +87,3 @@ return;

this.status = ProxyStatus_1.default.Alive;
data = result.data;
this.version = ProxyVersion_1.default.HTTP;
}

@@ -63,8 +93,28 @@ catch (error) {

}
if (this.status === ProxyStatus_1.default.Dead)
return;
this.setAnonymousInformation(data, myIP);
yield this.getProxyInformation();
});
}
checkWithSockProxy() {
return __awaiter(this, void 0, void 0, function* () {
try {
const resultWithSocks = yield this.generateSocksAxiosHandler("http://check-host.net/ip");
if (!request_1.checkRequestResponseIsGood(resultWithSocks.status)) {
this.status = ProxyStatus_1.default.Dead;
return;
}
this.status = ProxyStatus_1.default.Alive;
this.version = ProxyVersion_1.default.SOCKS;
}
catch (error) {
this.status = ProxyStatus_1.default.Dead;
}
});
}
handleCalculProxySpeed() {
if (this.timeTaken >= 3000)
this.speedLevel = ProxySpeedLevel_1.default.Slow;
if (this.timeTaken >= 1000)
this.speedLevel = ProxySpeedLevel_1.default.Medium;
if (this.timeTaken < 1000)
this.speedLevel = ProxySpeedLevel_1.default.Fast;
}
setAnonymousInformation(data, myIP) {

@@ -80,3 +130,3 @@ var obj = this.parseProxyJudgeInformation(data);

else {
this.anonymousLevel = ProxyAnonymousLevel_1.default.Unknwow;
this.anonymousLevel = ProxyAnonymousLevel_1.default.Unknown;
}

@@ -88,6 +138,20 @@ }

}
getProxyJudgeInformation() {
return __awaiter(this, void 0, void 0, function* () {
const resultProxyJudge = this.version === ProxyVersion_1.default.HTTP ?
yield this.generateHttpAxiosHandler(this.proxyJudgeSelected)
: yield this.generateSocksAxiosHandler(this.proxyJudgeSelected);
if (resultProxyJudge.status !== 200) {
this.status = ProxyStatus_1.default.Dead;
return "";
}
return resultProxyJudge.data;
});
}
getProxyInformation() {
return __awaiter(this, void 0, void 0, function* () {
try {
const { data, status } = yield this.generateAxiosHandler(this.proxyInformationProviderSelected);
const { data, status } = this.version === ProxyVersion_1.default.HTTP ?
yield this.generateHttpAxiosHandler(this.proxyJudgeSelected)
: yield this.generateSocksAxiosHandler(this.proxyJudgeSelected);
if (status == 200) {

@@ -114,6 +178,6 @@ let b = null;

/**
* Parse data of proxy judege to object with key:value
* @param {string} content proxy judge response
* @returns {object}
*/
* Parse data of proxy judege to object with key:value
* @param {string} content proxy judge response
* @returns {object}
*/
parseProxyJudgeInformation(content) {

@@ -131,16 +195,38 @@ var values = {};

}
generateAxiosHandler(url) {
generateHttpAxiosHandler(url) {
return __awaiter(this, void 0, void 0, function* () {
if (!this.axios)
throw new Error("No axios instance added");
return yield this.axios.get(url, {
timeout: this.timeout,
const option = {
proxy: {
host: this.address,
port: parseInt(this.port),
},
});
}
};
if (this.username && this.password && option.proxy) {
option.proxy.auth = {
username: this.username,
password: this.password
};
}
return request_1.generateAxiosHandler(this.axios, this.timeout, url, null, option);
});
}
generateSocksAxiosHandler(url) {
return __awaiter(this, void 0, void 0, function* () {
if (!this.axios)
throw new Error("No axios instance added");
const option = {
host: `socks://${this.address}:${this.port}`,
timeout: this.timeout,
};
if (this.username && this.password) {
option.userId = this.username;
option.password = this.password;
}
const agent = new socks_proxy_agent_1.SocksProxyAgent(option);
return request_1.generateAxiosHandler(this.axios, this.timeout, url, agent, null);
});
}
}
exports.default = Proxy;

@@ -5,4 +5,4 @@ declare enum ProxyAnonymousLevel {

Low = "Low",
Unknwow = "Unknwow"
Unknown = "Unknown"
}
export default ProxyAnonymousLevel;

@@ -8,4 +8,4 @@ "use strict";

ProxyAnonymousLevel["Low"] = "Low";
ProxyAnonymousLevel["Unknwow"] = "Unknwow";
ProxyAnonymousLevel["Unknown"] = "Unknown";
})(ProxyAnonymousLevel || (ProxyAnonymousLevel = {}));
exports.default = ProxyAnonymousLevel;

@@ -5,4 +5,4 @@ declare enum ProxySpeedLevel {

Fast = "Fast",
Unknwow = "Unknwow"
Unknown = "Unknown"
}
export default ProxySpeedLevel;

@@ -8,4 +8,4 @@ "use strict";

ProxySpeedLevel["Fast"] = "Fast";
ProxySpeedLevel["Unknwow"] = "Unknwow";
ProxySpeedLevel["Unknown"] = "Unknown";
})(ProxySpeedLevel || (ProxySpeedLevel = {}));
exports.default = ProxySpeedLevel;
declare enum ProxyStatus {
Dead = "Dead",
Alive = "Alive",
Unknwow = "Unknwow"
Unknown = "Unknown"
}
export default ProxyStatus;

@@ -7,4 +7,4 @@ "use strict";

ProxyStatus["Alive"] = "Alive";
ProxyStatus["Unknwow"] = "Unknwow";
ProxyStatus["Unknown"] = "Unknown";
})(ProxyStatus || (ProxyStatus = {}));
exports.default = ProxyStatus;
declare enum ProxyVersion {
SOCKS5 = "SOCKS5",
SOCKS4 = "SOCKS4",
SOCKS = "SOCKS",
HTTP = "HTTP",
Unknwow = "Unknwow"
Unknown = "Unknown"
}
export default ProxyVersion;

@@ -5,7 +5,6 @@ "use strict";

(function (ProxyVersion) {
ProxyVersion["SOCKS5"] = "SOCKS5";
ProxyVersion["SOCKS4"] = "SOCKS4";
ProxyVersion["SOCKS"] = "SOCKS";
ProxyVersion["HTTP"] = "HTTP";
ProxyVersion["Unknwow"] = "Unknwow";
ProxyVersion["Unknown"] = "Unknown";
})(ProxyVersion || (ProxyVersion = {}));
exports.default = ProxyVersion;
import Proxy from "./classes/Proxy";
import Result from "./models/Result";
import ResultCheckLinks from "./models/ResultCheckLinks";
declare class ProxyChecker {

@@ -9,2 +10,4 @@ proxiesList: Proxy[];

defaultProxyInformationProvider: string[];
availableProxyJudgesList: string[];
availableProxyInformationProvider: string[];
myIP: string;

@@ -30,2 +33,3 @@ timeout: number;

check(callback: Function | null): Promise<Result[]>;
private checkProxyJudgeAndInformationProviderLinks;
private getRandomProxyJudge;

@@ -35,3 +39,6 @@ private getRandomProxyInformationProvider;

private getMyIP;
checkProxyJudgeLinks(callback: Function | null): Promise<ResultCheckLinks[]>;
checkProxyInformationProviderLinks(callback: Function | null): Promise<ResultCheckLinks[]>;
private checkLink;
}
export default ProxyChecker;

@@ -18,3 +18,7 @@ "use strict";

const fs_1 = __importDefault(require("fs"));
const ResultCheckLinks_1 = __importDefault(require("./models/ResultCheckLinks"));
const LinkType_1 = __importDefault(require("./enum/LinkType"));
const axios_1 = __importDefault(require("axios"));
const request_1 = require("./helpers/request");
const splitter_1 = require("./helpers/splitter");
class ProxyChecker {

@@ -33,2 +37,4 @@ constructor() {

];
this.availableProxyJudgesList = [];
this.availableProxyInformationProvider = [];
this.myIP = "";

@@ -52,2 +58,5 @@ this.timeout = 0;

addOnly1Proxy(proxy) {
const { goodFormat } = splitter_1.proxySplit(proxy);
if (!goodFormat)
throw new Error('The proxy format is bad it should look like this: address:port or address:port:username:password');
this.addProxyInList(proxy);

@@ -91,8 +100,5 @@ return this;

let result = [];
if (this.proxyJudgesList.length === 0)
throw new Error("No proxy judge added");
if (this.proxyInformationProvider.length === 0)
throw new Error("No proxy information provider added");
if (this.proxiesList.length === 0)
throw new Error("No proxies added");
yield this.checkProxyJudgeAndInformationProviderLinks();
if (!this.myIP)

@@ -110,7 +116,21 @@ yield this.getMyIP();

}
checkProxyJudgeAndInformationProviderLinks() {
return __awaiter(this, void 0, void 0, function* () {
const resultCheckProxyJudgeLinks = yield this.checkProxyJudgeLinks(null);
const resultCheckProxyInformationProviderLinks = yield this.checkProxyInformationProviderLinks(null);
resultCheckProxyJudgeLinks.forEach(x => {
if (x.Result)
this.availableProxyJudgesList.push(x.Link);
});
resultCheckProxyInformationProviderLinks.forEach(x => {
if (x.Result)
this.availableProxyInformationProvider.push(x.Link);
});
});
}
getRandomProxyJudge() {
return this.getRandomInArray(this.proxyJudgesList);
return this.getRandomInArray(this.availableProxyJudgesList);
}
getRandomProxyInformationProvider() {
return this.getRandomInArray(this.proxyInformationProvider);
return this.getRandomInArray(this.availableProxyInformationProvider);
}

@@ -123,6 +143,3 @@ getRandomInArray(arrayTarget) {

try {
const { data } = yield axios_1.default({
method: 'get',
url: 'http://checkip.dyndns.org/',
});
const { data } = yield request_1.generateAxiosHandler(axios_1.default, this.timeout, 'http://checkip.dyndns.org/');
var r = /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/;

@@ -137,3 +154,46 @@ this.myIP = data.match(r)[0];

}
checkProxyJudgeLinks(callback) {
return __awaiter(this, void 0, void 0, function* () {
let result = [];
if (this.proxyJudgesList.length === 0)
return result;
result = yield Promise.all(this.proxyJudgesList.map((link) => __awaiter(this, void 0, void 0, function* () {
const linkResult = yield this.checkLink(LinkType_1.default.ProxyJudge, link);
if (callback)
callback(linkResult);
return linkResult;
})));
return result;
});
}
checkProxyInformationProviderLinks(callback) {
return __awaiter(this, void 0, void 0, function* () {
let result = [];
if (this.proxyInformationProvider.length === 0)
return result;
result = yield Promise.all(this.proxyInformationProvider.map((link) => __awaiter(this, void 0, void 0, function* () {
const linkResult = yield this.checkLink(LinkType_1.default.ProxyInformationProvider, link);
if (callback)
callback(linkResult);
return linkResult;
})));
return result;
});
}
checkLink(linkType, url) {
return __awaiter(this, void 0, void 0, function* () {
try {
const { status, data } = yield request_1.generateAxiosHandler(axios_1.default, this.timeout, url);
if (!request_1.checkRequestResponseIsGood(status) || !data) {
let msg = !request_1.checkRequestResponseIsGood(status) ? `Response code is ${status}` : 'No data received in response';
return new ResultCheckLinks_1.default(linkType, false, msg, url);
}
return new ResultCheckLinks_1.default(linkType, true, "", url);
}
catch (error) {
return new ResultCheckLinks_1.default(linkType, false, `Exception - ${error.message}`, url);
}
});
}
}
exports.default = ProxyChecker;
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const ProxyAnonymousLevel_1 = __importDefault(require("../enum/ProxyAnonymousLevel"));
const ProxySpeedLevel_1 = __importDefault(require("../enum/ProxySpeedLevel"));
const ProxyStatus_1 = __importDefault(require("../enum/ProxyStatus"));
const ProxyVersion_1 = __importDefault(require("../enum/ProxyVersion"));
class Result {
constructor(proxyAnonymousLevel, proxySpeedLebel, proxyStatus, proxyVersion, proxy, proxyJudgeSelected, timeTaken, proxyInformationProviderSelected, country) {
this.ProxyAnonymousLevel = ProxyAnonymousLevel_1.default.Unknown;
this.ProxySpeedLevel = ProxySpeedLevel_1.default.Unknown;
this.ProxyStatus = ProxyStatus_1.default.Unknown;
this.ProxyVersion = ProxyVersion_1.default.Unknown;
this.ProxyAnonymousLevel = proxyAnonymousLevel;

@@ -6,0 +17,0 @@ this.ProxySpeedLevel = proxySpeedLebel;

{
"name": "nodejs-proxy-checkerv2",
"version": "1.1.0",
"version": "1.2.0",
"description": "It's simple Proxy Checker, get proxy status, anonymous level, type, time, country",

@@ -36,4 +36,5 @@ "main": "dist/index.js",

"dependencies": {
"axios": "^0.21.0"
"axios": "^0.21.0",
"socks-proxy-agent": "^5.0.0"
}
}

@@ -7,4 +7,4 @@ # NodeJS-Proxy-CheckerV2

- [x] Proxy country
- [ ] Type
- [ ] Proxy Time
- [x] Proxy type (HTTP or SOCKS)
- [x] Proxy time

@@ -17,3 +17,3 @@ ## Install

# How to use ?
## How to use ?

@@ -32,6 +32,6 @@ ```javascript

### Load proxies with file
#### Load proxies with file
One proxy per line and in this format: address: port
```javascript

@@ -46,6 +46,6 @@ const instance =new ProxyChecker()

### Load proxys with string array
#### Load proxys with string array
One proxy per line and in this format: address: port
```javascript

@@ -66,3 +66,3 @@ const proxies = [

### Load only one proxy
#### Load only one proxy

@@ -78,3 +78,3 @@ ```javascript

### You can combine the 3
#### You can combine the 3

@@ -94,3 +94,3 @@ ```javascript

You can put a callback in order to have the result of each live proxy test so as not to wait for everything
#### You can put a callback in order to have the result of each live proxy test so as not to wait for all

@@ -106,3 +106,3 @@ ```javascript

You don't have to put addDefaultProxyJudge and addDefaultProxyInformationProvider if you have yours you can add like this
#### You don't have to put addDefaultProxyJudge and addDefaultProxyInformationProvider if you have yours you can add like this

@@ -121,3 +121,3 @@ ```javascript

Or combine default and yours
#### Or combine default and yours

@@ -136,4 +136,23 @@ ```javascript

#### You can check the judges proxy link and proxy informations provider link with:
:warning: *Links are automatically checked and filtered when called "check()" those that don't work are ignored*
```javascript
const instance =new ProxyChecker()
const result = await instance.checkProxyJudgeLinks(null) //or instance.checkProxyJudgeLinks((val) => console.log(val)) for direct
const result2 = await instance.checkProxyInformationProviderLinks(null) // or instance.checkProxyInformationProviderLinks((val) => console.log(val)) for direct
```
## Results
- [check()](./src/models/Result.ts)
- [checkProxyInformationProviderLinks()](./src/models/ResultCheckLinks.ts)
- [checkProxyJudgeLinks()](./src/models/ResultCheckLinks.ts)
## Dependencies
- [axios](https://www.npmjs.com/package/axios)
- [socks-proxy-agent](https://www.npmjs.com/package/socks-proxy-agent)