Archive for the 'proxy.pac' Category

Multi-homed PCs and Proxy.pac

November 30, 2016

If writing a proxy.pac file for a site, you may need to determine which proxy to use based on the current IP address. Should your browser host have multiple IP addresses, e.g. you’re running VirtualBox in host-only mode, you may find the built in myIpAddress() method returns the wrong IP address. The following JS extract uses the myIpAddressEx() method – this returns all configured IP addresses as a ‘;’ terminated string.

The following defines myips.isInNet(ip, range) to replace the built in method isInNet (myIpAddress(), ip, range) and will check all configured ipv4 addresses rather than the random single value that your browser picks.

var myips = myIpAddressEx().split(";");
myips.isInNetX = function(ip, range) {
   var matchOne = function (acc, myip) {
       return acc || myip.startsWith("[") ? false : isInNet (myip, ip, range)
   return this.reduce(matchOne, false);