Difference between revisions of "Rotate IPs"

From FoxyProxy Documentation
Jump to: navigation, search
Line 43: Line 43:
  
 
* You must hard-code the list of proxies in the PAC file :(
 
* You must hard-code the list of proxies in the PAC file :(
 
 
  <nowiki>
 
  <nowiki>
 +
 +
var proxies = ["PROXY 123.123.123.123:9050", "PROXY 192.168.1.3:8080",
 +
"PROXY 108.54.23.11:6667", "PROXY 106.25.84.11:6667", "PROXY 143.51.88.76:6667"];
 +
 +
function FindProxyForURL(url, host) {
 +
  return proxies[getRandomInt(0, proxies.length)];
 +
}
 +
 +
function getRandomInt(firstIndex, lastIndex) {
 +
  // Inclusive
 +
  // Thanks, http://www.shawnolson.net/a/789/make_javascript_mathrandom_useful.html
 +
  return firstIndex + (Math.floor((lastIndex - firstIndex + 1) * Math.random()))
 +
}
 
  </nowiki>
 
  </nowiki>

Revision as of 16:21, 9 May 2013

How to use a PAC file to automatically rotate IPs

This PAC script round-robin rotates through X number of proxies every Y seconds.

  • You must hard-code the list of proxies in the PAC file :(
  • The secondsToSwitchAfter variable controls how frequently the proxies should be rotated
 // PAC file to switch IP addresses every 3 seconds across 5 IP addresses

 var proxies = ["PROXY 123.123.123.123:9050", "PROXY 192.168.1.3:8080",
 "PROXY 108.54.23.11:6667", "PROXY 106.25.84.11:6667", "PROXY 143.51.88.76:6667"],
  t1 = new Date().getTime(), counter = 1;

 var secondsToSwitchAfter = 3;

 function FindProxyForURL(url, host) {
   var t2 = new Date.getTime();
   if (t2 - t1 > secondsToSwitchAfter * 1000)
     counter++;
   t1 = t2;
   return proxies[counter % proxies.length];
 }
 

This PAC script round-robin rotates through X number of proxies. The proxies are switched for each URL request.

  • You must hard-code the list of proxies in the PAC file :(

 var proxies = ["PROXY 123.123.123.123:9050", "PROXY 192.168.1.3:8080",
 "PROXY 108.54.23.11:6667", "PROXY 106.25.84.11:6667", "PROXY 143.51.88.76:6667"],
  counter = -1;

 function FindProxyForURL(url, host) {
   counter++;
   if (counter > proxies.length) counter = -1;
   return proxies[counter];
 }
 

This PAC script randomly rotates through X number of proxies. The proxies are switched for each URL request.

  • You must hard-code the list of proxies in the PAC file :(

 var proxies = ["PROXY 123.123.123.123:9050", "PROXY 192.168.1.3:8080",
 "PROXY 108.54.23.11:6667", "PROXY 106.25.84.11:6667", "PROXY 143.51.88.76:6667"];

 function FindProxyForURL(url, host) {
   return proxies[getRandomInt(0, proxies.length)];
 }

 function getRandomInt(firstIndex, lastIndex) {
   // Inclusive
   // Thanks, http://www.shawnolson.net/a/789/make_javascript_mathrandom_useful.html
   return firstIndex + (Math.floor((lastIndex - firstIndex + 1) * Math.random()))
 }