Last active
March 28, 2024 08:05
-
-
Save raghur/7aba1d879d49f30e7c833875d79d966b to your computer and use it in GitHub Desktop.
Proxy pac file for switching proxy based on IP - works with Firefox & Chromium.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function FindProxyForURL(url, host) | |
{ | |
// firefox - Ctrl-Shift-J Chrome/Chromium: chrome://net-internals/#events | |
var debug = true; | |
var log = function() { | |
if (debug) { | |
var args = Array.prototype.slice.call(arguments); | |
alert(args.join(" ")); | |
} | |
} | |
var bypassProxy = false; | |
log("Checking for availability of myIpAddressEx:", typeof(myIpAddressEx) == "function"); | |
// firefox doesn't have myIpAddressEx - but it does seem to return the | |
// right IP | |
if (typeof(myIpAddressEx) != "function") { | |
log("myIpAddress returns: ", myIpAddress()); | |
bypassProxy = myIpAddress() == '10.8.0.6' || myIpAddress().startsWith("192.168.1."); | |
} else { | |
// chromium seems to pick the first IP - in my case, a virtualbox HOST | |
// only IP. So check in all IPs returned by myIpAddressEx | |
var ips = myIpAddressEx().split(";"); | |
log("myIpAddressEx returns", myIpAddressEx()); | |
for(i=0; i< ips.length; i++) { | |
if (ips[i] == "10.8.0.6" || ips[i].startsWith("192.168.1.")) { | |
bypassProxy = true; | |
break; | |
} | |
} | |
} | |
log("Can bypass proxy: ", bypassProxy); | |
if (bypassProxy) | |
{ | |
log ("DIRECT") | |
return "DIRECT"; | |
} | |
else | |
{ | |
log( "PROXY") | |
return "PROXY 10.98.2.8:8080"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment