[Top]

Proxy configuration server [Perl]

Still a different proxy
When moving a laptop from office to home to a customer network, it is often necessary to change the proxy settings of the browser.
The laptop itself is a good place to host a proxy configuration server, running this HTTP daemon that knows how to act depending on its IP address.
This script implements a small HTTP server that provides the appropriate proxy configuration based on the current IP address.
The proxy configuration specification may be found here .
Usage
The script is written in Perl . A free Perl distribution may be found at www.activestate.com .
The script is launched by double-clicking on it or by typing at the command prompt and pressing Enter but in a normal situation should be launched at startup:
perl ProxyConfig.pl
The defaults of the scripts are:
my $configFile 	= 'c:/Perl/ProxyConfig.properties';
my $port 	= 8081;

my $ipMarker  	= 'IP';
my $excludedIp  = '192\.168\.\d\.1'; # VMware addresses
The $configFile is the file containing the regular expressions on IP addresses and the associated proxy.
The $port is the IP port the server is listening on.
The $ipMarker helps to recognize a line of the command ipconfig containing an IP address.
The pattern $excludedIp is used to reject a local address that may be the one of a virtual device as VMware Workstation network adapters.
Configuration
The configuration file contains key=value pairs, for example:
^192\.168=DIRECT
^158=PROXY pxy.corporate.com:80
.*=DIRECT
The key is a Perl regular expression attempted to match with the IP address of the machine.
Keys are processed in the precedence order as found in the configuration file, the first match being the result.
The value is either:
  • the keyword DIRECT for a direct connection to Internet, or
  • the pattern PROXY name:port containing the name or address of the Internet proxy, optionally followed by the port to be used.
Browser setup
The browser setup has to call this service to get its proxy configuration:
Mozilla family
Select 'Tools', 'Options...', 'Connection settings...'.
Select 'Automatic proxy configuration URL'.
The appropriate setting is http://localhost:8081/proxy.pac .
[Mozilla settings]
Internet Explorer
Select 'Tools', 'Internet Options...', 'Connections', 'LAN Settings...'.
Check 'Use automatic configuration script'.
The appropriate setting for the 'Address' is http://localhost:8081/wpad.dat .
[IE settings]
Download
The current version is 1.0.
The ZIP file contains the scripts: ProxyConfig.zip .
[Top]