proxy-rotator-agent
v0.0.8
Published
HTTP proxy rotator tunneling agent
Downloads
4
Readme
proxy-rotator-agent
This agent rotates requests trought especified proxies
If 2 proxies are specified First request goes trought first proxy Second request goes trought seconde proxy Third request goes trought first proxy
for mikeal/request
const request = require('request');
const ProxyRotator = require('proxy-rotator-agent')
const agent = new ProxyRotator({
proxies: [
{ proxy: { host: '10.0.0.1', port: 3128, proxyAuth: 'pass', headers: { 'user-agent': 'nautilus' }}},
{ proxy: { host: '10.0.0.2', port: 4545, proxyAuth: 'proxy2pass', headers: { 'user-agent': 'firefox' }}}
]
})
function optionalCallback(err, httpResponse, body) {
if(err) return console.error(err);
console.log(err, body);
}
const options = {
uri: 'https://httpbin.org/ip',
json: true,
agent,
};
request(
options,
optionalCallback
)
request(
options,
optionalCallback
)
Output
{
ip: '10.0.0.1'
}
{
ip: '10.0.0.2'
}
for native https request
const https = require('https');
const ProxyRotator = require('proxy-rotator-agent')
const agent = new ProxyRotator({
proxies: [
{ proxy: { host: '10.0.0.1', port: 3128, proxyAuth: 'pass', headers: { 'user-agent': 'nautilus' }}},
{ proxy: { host: '10.0.0.2', port: 4545, proxyAuth: 'proxy2pass', headers: { 'user-agent': 'firefox' }}}
]
})
const options = {
hostname: 'httpbin.org',
port: 443,
path: '/ip',
agent,
};
// Make a request
function request(options) {
const req = https.request(options);
req.on('response', (res) => {
res.on('data', (data) => {
console.log(data.toString())
});
});
req.on('error', (err) => {
console.error(err);
});
req.end();
}
request(options)
request(options)
Output:
{
"origin": "10.0.0.1"
}
{
"origin": "10.0.0.2"
}
for axios