Proxy Rotator Script Generator
Generate production-ready rotating proxy scripts for Node.js and Python.
npm install axios http-proxy-agent https-proxy-agent1/**2 * Proxy Rotator Script3 * Generated by ProxyHorizon (7/11/2026)4 *5 * Install dependencies:6 * npm install axios http-proxy-agent https-proxy-agent7 *8 * Usage:9 * const { ProxyRotator } = require('./proxy-rotator');10 * const rotator = new ProxyRotator();11 * const res = await rotator.fetch('https://httpbin.org/ip');12 */1314const axios = require('axios');15const { HttpProxyAgent } = require('http-proxy-agent');16const { HttpsProxyAgent } = require('https-proxy-agent');1718// ── Configuration ──────────────────────────────────────────────1920const PROXIES = [21 'http://1.2.3.4:8080',22 'http://5.6.7.8:3128',23 // Add your proxies here24];2526const CONFIG = {27 strategy: 'round_robin',28 rotateTrigger: 'request',29 interval: 5,30 timeout: 10000,31 maxRetries: 3,32 removeDead: true,33};3435// ── ProxyRotator Class ─────────────────────────────────────────3637class ProxyRotator {38 constructor(proxies = PROXIES, config = CONFIG) {39 this.proxies = [...proxies];40 this.config = config;41 this.index = 0;42 this.reqCount = 0;43 this.lastRotateTime = Date.now();44 this.usage = new Map();45 this.proxies.forEach(p => this.usage.set(p, 0));46 }4748 // Pick next proxy based on strategy49 getNextProxy() {50 if (this.proxies.length === 0) throw new Error('No proxies available');5152 let proxy;53 switch (this.config.strategy) {54 case 'random':55 proxy = this.proxies[Math.floor(Math.random() * this.proxies.length)];56 break;57 case 'least_used':58 proxy = this.proxies.reduce((min, p) =>59 (this.usage.get(p) || 0) < (this.usage.get(min) || 0) ? p : min60 );61 break;62 default: // round_robin63 proxy = this.proxies[this.index % this.proxies.length];64 this.index++;65 }6667 this.usage.set(proxy, (this.usage.get(proxy) || 0) + 1);68 return proxy;69 }7071 // Check if it's time to rotate72 shouldRotate() {73 this.reqCount++;74 switch (this.config.rotateTrigger) {75 case 'n_requests':76 return this.reqCount % this.config.interval === 0;77 case 'n_seconds': {78 const elapsed = (Date.now() - this.lastRotateTime) / 1000;79 if (elapsed >= this.config.interval) {80 this.lastRotateTime = Date.now();81 return true;82 }83 return false;84 }85 default:86 return true; // every request87 }88 }8990 // Remove a failed proxy from the pool91 removeProxy(proxy) {92 this.proxies = this.proxies.filter(p => p !== proxy);93 this.usage.delete(proxy);94 console.log(`[Rotator] Removed ${proxy}. ${this.proxies.length} remaining.`);95 }9697 // Make an HTTP request through a rotating proxy98 async fetch(url, options = {}) {99 let lastError;100101 for (let attempt = 0; attempt < this.config.maxRetries; attempt++) {102 const proxy = (this.shouldRotate() || attempt > 0)103 ? this.getNextProxy()104 : this.proxies[this.index % this.proxies.length];105106 try {107 const agent = url.startsWith('https')108 ? new HttpsProxyAgent(proxy)109 : new HttpProxyAgent(proxy);110111 const response = await axios({112 url,113 ...options,114 httpAgent: agent,115 httpsAgent: agent,116 timeout: this.config.timeout,117 });118119 console.log(`[Rotator] ${proxy} -> ${response.status}`);120 return response;121 } catch (error) {122 lastError = error;123 console.warn(`[Rotator] ${proxy} failed (attempt ${attempt + 1}): ${error.message}`);124125 if (this.config.removeDead && this.proxies.length > 1) {126 this.removeProxy(proxy);127 }128 }129 }130131 throw lastError;132 }133134 // Get usage statistics135 getStats() {136 return {137 totalProxies: this.proxies.length,138 totalRequests: this.reqCount,139 usage: Object.fromEntries(this.usage),140 };141 }142}143144// ── Usage Example ──────────────────────────────────────────────145146(async () => {147 const rotator = new ProxyRotator();148149 try {150 const res = await rotator.fetch('https://httpbin.org/ip');151 console.log('Response:', res.data);152 console.log('Stats:', rotator.getStats());153 } catch (err) {154 console.error('All proxies failed:', err.message);155 }156})();157158module.exports = { ProxyRotator };159What Is the Proxy Rotator Script Generator?
The Proxy Rotator Script Generator builds production-ready proxy-rotation code for Node.js and Python in seconds. Choose your rotation strategy, retry behavior, and dead-proxy handling, and the tool outputs clean, commented code you can drop straight into a scraper. It is the fastest way to add reliable IP rotation without writing the boilerplate yourself.
Key Features
Why You Need Proxy Rotation
Sending every request through one IP gets you rate-limited and banned fast. Rotation spreads requests across a pool of proxies so each address makes only a fraction of the traffic, mimicking many separate users. Combined with retries and dead-proxy removal, rotation is what keeps a large scraping job running to completion instead of stalling on blocks.
What the Generated Script Does
The generated code loads your proxy pool, selects a proxy per request using your chosen strategy, and automatically retries failed requests on a different proxy. It tracks failures and drops dead proxies from rotation so your scraper does not keep hitting the same broken endpoint. You get a tested pattern instead of reinventing it.
Common Use Cases
- Adding IP rotation to a Python or Node.js scraper
- Building a resilient pipeline that survives dead proxies
- Distributing requests to avoid rate limits and bans
- Prototyping a rotation strategy before integrating it
Frequently Asked Questions
Which languages are supported?
The generator outputs ready-to-run scripts for both Node.js (JavaScript) and Python, the two most common languages for web scraping and automation.
What rotation strategies can I choose?
You can pick strategies such as round-robin, which cycles through proxies in order, or random selection. Both spread load across your pool; round-robin is more even, while random is less predictable.
Does the script handle dead proxies?
Yes. The generated code detects failed requests, retries them on a different proxy, and removes consistently failing proxies from rotation so your job keeps running smoothly.
Are my proxies sent anywhere?
No. The script is generated locally in your browser and you supply your real proxies only when you run the code on your own machine. Nothing is uploaded by the generator.
Can I customize the generated code?
Absolutely. The output is clean, commented, and standalone, so you can adjust timeouts, headers, concurrency, and logic to fit your specific project.
Looking for proxies to use with this tool?
Browse the proxy directory