I have many big lists of free proxies on text files. I need to write a small program which can test these proxies if they work or not. To do that i need to send ping on each proxy, but this is not a 100% solution because many proxies block ping. So someone tell me to use "extended ping" mathod. With this method i will be able to send to any site a ping using a proxy. So i can understand if the proxy is alive. After i found the alive proxies, can Java set them as system(operation system's) default proxy? Is this possible on latest version of SunJava for Linux and Windows?

Thank you!

Edited by cemali_ys: n/a

5 Years
Discussion Span
Last Post by JamesCherrill

JamesCherrill i look your links which you gave me. I write this code to test the functions:

import java.net.*;

public class Main {
	public static void main(String[] args) {
		                SocketAddress addr = new InetSocketAddress("", 3128);
				Proxy proxy = new Proxy(Proxy.Type.HTTP, addr);
				URL url;
				URLConnection conn;
				url = new URL("http://www.google.com/");	
				conn = url.openConnection(proxy);
					System.out.println("con1 eror");
				URL url2 = new URL("http://www.google.com/");
				URLConnection conn2 = url2.openConnection(Proxy.NO_PROXY);
					System.out.println("con2 eror");
                catch(Exception e){

But it never gives me any error. I change the google.com with www.rewrfewfvedfwefeFEWRE.com it does not give me an error. I think this is not a way to understand if the proxy works or not. Am i right ? Can you please help me again ?

Edited by cemali_ys: n/a


I tried something very similar, but I went on to try to read the site via the proxy. Here's the code I used - - the proxy is pretty poor, so this worked about 1/2 the time.

try {
         // create a Proxy at a known internet address (this one is Chinese and slow)...
         SocketAddress proxyAddr = new InetSocketAddress("", 8080);
         Proxy proxy = new Proxy(Proxy.Type.HTTP, proxyAddr);
         // create a URL and try to connect to it via the proxy...
         URL url = new URL("http://google.com"); // hnown high-availability site
         URLConnection urlc = url.openConnection(proxy); // connect via proxy
         // read input from site and print it (should be Google's http code)...
         InputStream in = urlc.getInputStream(); 
         char c;
         while ((c = (char) in.read()) != -1) {
      } catch (Exception e) {
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.