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); 
}
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: