Ahaha, tiba-tiba postingannya gini.. Jadi, di kantor sebulan sekali gw harus menulis di wiki lokal sana. Karena menulis buat gw merupakan suatu hal yang tidak terjadi secara alamiah sehingga menghabiskan waktu dan tenaga, sayang dong kalo adanya di wiki lokal aja. Jadi di tulis disini juga. Selain itu, sekarang gw uda telat blm nulis, bsk senin ga ke kantor, jadi ditulis disini supaya asisten saya saudari miri bisa memasukannya ke wiki, bukankah begitu mir?hihihi.. becanda mir..makasi yaaaa.. salam buat live update..kasitau kalo ito marah2 karena gabisa baca kode gw yg brantakan..hii, deg2an.. Baiklah, enuff chit chat, mari kita mulai tulisan cupu sok2 technicalnya:


To develop a desktop application that requires an internet connection, we might need to create a connection using proxy. Though in some cases we can ask user to provide the proxy setting that we need to use, in many other cases, the user themselves might not know the proxy setting that they are using. In such cases, detecting the proxy setting automatically might just be the answer. In this article, we will discuss on how to detect the proxy setting in Windows.

Proxy settings in windows
To know what the available proxy settings in Windows are, we can see the settings in the Internet Explorer. There are several options available:

1. Automatically detect settings.

2. Use automatic configuration script.

3. Use a proxy server for your LAN (manual configuration).

Where the information are stored

Information about this setting can be retrieved in the registry.

The registry key you should be looking for are available in the following location:
HKEY_CURRENT_USER>Software>Microsoft>Windows>CurrentVersion>Internet Settings

How to determine the setting

Different proxy settings will create different keys or different values in the registry as follows:

  • ProxyEnable: this key can be set to 0 or 1. The value 1 specifies that the manual configuration is used.
  • ProxyServer: if we specify manual configuration, the Address and Port of the proxy server is specified in this key with the format of <server address>:<server port> (i.e. “127.0.0.0:8080″)
  • ProxyOverride: for manual proxy settings, sometimes some local addresses will require you to bypass the proxy in order to be able to establish the connection. This key specifies which addresses are suppose to be bypassed. Different addresses are separated with a semicolon.
  • AutoConfigURL: when we specify to use an automatic configuration file for the proxy, the address to the automatic configuration file is available as a value in this key. The configuration file is a Proxy Auto Configuration (.pac) file. This file contains javascript functiona which will determine which proxy to use to connect to a particular server address.

Implementation tips

  • Reading Registry. To implement automatic detection of proxy setting in Windows, first, we need to be able to read the registry. For Java, we can use library such as the jRegistryKey to read and write to the registry.
  • Using .pac file. As a .pac file contains javascripts, it is most likely that we will not be able to use the file directly except if we create our on interpreter for javascript. However, a library is already available to parse such file, such as the pacparser. This library is a C library which allows you to retrieve the proxy that you should use to connect to a particular server address according to the .pac file.