Proxies are very widely used to rote the traffic from a particular server. A proxy can be a HTTP proxy or it can be for an specific protocol. But today we are concerned about the HTTP proxy that we set in our web browsers. For example if you go to Internet Explorer settings and click Connections –> LAN Settings –> Advanced, you can see the current proxy settings. You also get to edit these settings.

Sample Code

My purpose is to show yu how can we detect proxy settings for Internet Explorer through Java program. So let us look at the code for the same:

import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.ProxySelector;
import java.net.URI;
import java.util.Iterator;
import java.util.List;

public class Test{

	public static void main(String[] args) {
		 try {

	            System.setProperty("java.net.useSystemProxies","true");
	            List l = ProxySelector.getDefault().select(new URI("http://www.google.com/"));

	            for (Iterator iter = l.iterator(); iter.hasNext(); ) {

	                Proxy proxy = (Proxy) iter.next();

	                System.out.println("proxy hostname : " + proxy.type());

	                InetSocketAddress addr = (InetSocketAddress)
	                    proxy.address();

	                if(addr == null) {

	                    System.out.println("No Proxy");

	                } else {

	                    System.out.println("proxy hostname : " + 
	                            addr.getHostName());

	                    System.out.println("proxy port : " + 
	                            addr.getPort());

	                }
	            }
	        } catch (Exception e) {
	            e.printStackTrace();
	        }
	}

}

Here I am trying to make a connection to google.com by using the current proxy settings. Please note that the above program will work for any version of IE currently running on your Windows machine. This code can’t be used for Google Chrome and Mozilla Firefox on Windows.

As you can see in the above code that there is a Proxy class which represents the proxy settings for the browser in Java code. Also the system property “java.net.useSystemProxies” also needs to be highlighted. A sample run for the above code in windows with IE 9 produces the following output:

proxy hostname : DIRECT
No Proxy

Proxy for other browsers

It is very easy to get proxy settings for Internet Explorer in Windows because it is tightly coupled with the operating system. The same is applicable for Safari on Mac OS. If you are really interested in getting the proxy settings for non-native web browsers like Google Chrome and Mozilla Firefox on windows using Java code then you need some third party libraries which can read the settings of these browsers. See the reference section for a fully working cross browser proxy detection utility with source code.

Reference

Proxy-Vole on Google Code
Proxy Settings for Java

How to detect browser proxy using Java program admin Core Java
Proxies are very widely used to rote the traffic from a particular server. A proxy can be a HTTP proxy or it can be for an specific protocol. But today we are concerned about the HTTP proxy that we set in our web browsers. For example if you go...
<p>Proxies are very widely used to rote the traffic from a particular server. A proxy can be a HTTP proxy or it can be for an specific protocol. But today we are concerned about the HTTP proxy that we set in our web browsers. For example if you go to Internet Explorer settings and click Connections --> LAN Settings --> Advanced, you can see the current proxy settings. You also get to edit these settings.</p> <h2>Sample Code</h2> <p>My purpose is to show yu how can we detect proxy settings for Internet Explorer through Java program. So let us look at the code for the same:</p> 1 <p>Here I am trying to make a connection to google.com by using the current proxy settings. Please note that the above program will work for any version of IE currently running on your Windows machine. This code can't be used for Google Chrome and Mozilla Firefox on Windows.</p> <p>As you can see in the above code that there is a Proxy class which represents the proxy settings for the browser in Java code. Also the system property "java.net.useSystemProxies" also needs to be highlighted. A sample run for the above code in windows with IE 9 produces the following output:</p> <blockquote>proxy hostname : DIRECT No Proxy</blockquote> <h2>Proxy for other browsers</h2> <p>It is very easy to <strong>get proxy settings for Internet Explorer</strong> in Windows because it is tightly coupled with the operating system. The same is applicable for Safari on Mac OS. If you are really interested in getting the proxy settings for non-native web browsers like Google Chrome and Mozilla Firefox on windows using Java code then you need some third party libraries which can read the settings of these browsers. See the reference section for a fully working cross browser proxy detection utility with source code.</p> <h2>Reference</h2> <a href="http://code.google.com/p/proxy-vole/">Proxy-Vole on Google Code</a> <a href="http://www.java.com/en/download/help/proxy_setup.xml">Proxy Settings for Java</a>