Hello!

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 5 Years Ago by cemali_ys: n/a

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) {
		try{
		                SocketAddress addr = new InetSocketAddress("149.169.227.131", 3128);
				Proxy proxy = new Proxy(Proxy.Type.HTTP, addr);
				URL url;
				URLConnection conn;
				url = new URL("http://www.google.com/");	
				conn = url.openConnection(proxy);
				if(conn==null)
				{
					System.out.println("con1 eror");
				}
					
				URL url2 = new URL("http://www.google.com/");
				URLConnection conn2 = url2.openConnection(Proxy.NO_PROXY);
				if(conn2==null)
				{
					System.out.println("con2 eror");
				}		
		}
                catch(Exception e){
			System.out.println("error");
		}
		System.out.println("finish");
	}
}

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 5 Years Ago 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("118.182.20.242", 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) {
            System.out.print(c); 
         }
      } catch (Exception e) {
         e.printStackTrace();
      }
This article has been dead for over six months. Start a new discussion instead.