proxyratemanager
ES6 JS classes for http/https Proxy Requests and IP rate limiting
Installation
npm install proxyratemanager --save
Usage
This is a module to facilitate proxying requests while staying within specified rate limits per action.
NOTE: This module heavily relies on AdvancedRequest. Good understanding of it is pretty important to use this.
Main features:
- Automatically launch tor and change exit node
- Specification of multiple circuits through proxies or tor
- Automatic circuit "health" management to help avoid circuits during their downtime
- Specify actions to be limited by name per IP per unit time
- Specify pool of proxies to be randomly or specifically used
Example setup
const {ProxyRateManager, AdvancedProxiedRequest} = require('proxyratemanager');
let proxyRateManager = new ProxyRateManager({
EXTERNAL_IP_CHECK_URL: `https://www.myexternalip.com/raw`,
});
let oneDayInMs = 1000 * 60 * 60 * 24;
proxyRateManager.addRateLimitActionKey({key: "apirequest1", limit: 1200, timeForRateReset: oneDayInMs});
proxyRateManager.addRateLimitActionKey({key: "apirequest2", limit: 1200, timeForRateReset: oneDayInMs});
await proxyRateManager.initWithCircuits([
{
"name": "login_proxy", "port":7777,"username":"root","password":"pwpwpw","host":"example.com",
addToCyclingCircuitPool: false,
},
{"type": "http", "port":7777,"username":"root","password":"pwpwpw","host":"example2.com"},
{"isLocalTor": true, "port":9050,"host":"3.3.3.3"},
{"port":7777,"username":"root","password":"pwpwpw","host":"1.1.1.1"},
{"port":7777,"username":"root","password":"pwpwpw","host":"2.2.2.2"},
{"port":7777,"host":"3.3.3.3"},
]);
proxyRateManager.addCircuit({"port":7777,"username":"root","password":"pwpwpw","host":"4.4.4.4"});
Create a ProxyClient to send requests using the pool for this manager
let proxyClient = proxyRateManager.createClient();
let req = new AdvancedProxiedRequest({
url: `http://example.com/api/v1/dosomething`,
method: 'GET',
name: "apirequest1",
reqArgs: {
proxyClient: proxyClient
},
});
await proxyClient.changeIPIfNecessary("apirequest1");
let jsonData = await req.runAsync();
if (jsonData.something_is_wrong_with_request_results) {
await proxyClient.forceIPChangeImmediately();
} else {
proxyClient.reportNewAction("apirequest1");
}
Get details about current circuit for this client object
let exitIP = proxyClient.getCurrentIP();
let circuitIdentifier = proxyClient.circuit.getIdentifier();
let health = proxyClient.circuit.getHealth();
console.log(`[D] proxyClient details: exitIP=${exitIP} circuitIdentifier=${circuitIdentifier} health=${health}`);
A lot goes into this module. Reading the code is useful to understand more of how it works.
Credits
http://x64projects.tk/