import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.net.UnknownHostException;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;


public class TCPConnectTest {

	public static void main(String[] args) throws IOException, InterruptedException {
		
		String inputfile;
		String defaultinput = "outsideresults";
		try{
			inputfile = args[0];
		}catch(Exception e){
			System.out.println("Defaulting to input file " + defaultinput);
			inputfile = defaultinput;
		}
		
		int cores = Runtime.getRuntime().availableProcessors()-1;
		cores = 2000;
		ThreadPoolExecutor es = (ThreadPoolExecutor) Executors.newFixedThreadPool(cores);
		
		try(BufferedReader br = new BufferedReader(new FileReader(inputfile))) {
		    for(String line; (line = br.readLine()) != null; ) {
		        
		    	final String linef = line;
		    	Runnable run = (new Runnable() {
					
					@Override
					public void run() {
						
						
						String serverN = linef;
						try{
							//if there is a ,
							serverN = serverN.substring(0, serverN.indexOf(','));
						}catch(StringIndexOutOfBoundsException e){}
						serverN = serverN.replaceAll("http://", "");
						serverN = serverN.replaceAll("https://", "");
						serverN = serverN.replaceAll("ftp://", "");
						serverN = serverN.replaceAll("ftps://", "");
						serverN = serverN.replaceAll("/", "");
						serverN = serverN.trim();
						serverN = serverN.toLowerCase();
						
				    	String result = "Error";
				    	//int trys = 0;
				    	//while (trys-- >= 0 && !("Success".equals(result))){
					    	try{
					    		testConnection(serverN);
					    		result = "Success";
					    	}catch(Exception e){
					    		result = e.getClass().getSimpleName();
//					    		try {
//					    			//Sleep for a moment before trying again
//									Thread.sleep(5000);
//								} catch (InterruptedException e1) {
//									e1.printStackTrace();
//								}
					    	}
				    	//}
				    	
				    	System.out.println(serverN + "," + 80 + "," + result);
				    	
		    	
					}
				});
		    	
		    	es.execute(run);
		    	
		    }
		   
		    
		}
		
		es.shutdown();
		
		//wait forever
		es.awaitTermination(9999, TimeUnit.DAYS);
		System.out.println("#######Finished######");
		
		
		

	}
	
	
	
	
	
	public static void testConnection(String server) throws UnknownHostException, IOException{
		
		URL u = new URL("http://" + server);
		URLConnection c = u.openConnection();
		
		c.connect();
		
		//System.out.println(c.getContentLength());
		
		
//		Socket client = new Socket(server, port);
//        System.out.println("Just connected to " + client.getRemoteSocketAddress());
//        OutputStream outToServer = client.getOutputStream();
//        DataOutputStream out = new DataOutputStream(outToServer);
//
//        out.writeUTF("GET / HTTP/1.1\n\n");
//        InputStream inFromServer = client.getInputStream();
//        DataInputStream in = new DataInputStream(inFromServer);
//        System.out.println("Server says " + in.readUTF());
//        client.close();
		
	}
	
	
	

}

@@ -632,16 +632,62 @@
 %0A%09%09%7D%0A%09%09%0A
+%09%09%0A%09%09System.setProperty(%22http.agent%22, %22%22);%0A%09%09%0A
 %09%09int co
@@ -840,16 +840,51 @@
 res);%0A%09%09
+final String block = %22forblocking%22;
 %0A%09%09try(B
@@ -1702,18 +1702,16 @@
 %09%09%09    %09
-//
 int trys
@@ -1713,17 +1713,17 @@
  trys = 
-0
+4
 ;%0A%09%09%09%09  
@@ -1725,18 +1725,16 @@
 %09%09%09    %09
-//
 while (t
@@ -1936,26 +1936,24 @@
 mpleName();%0A
-//
 %09%09%09%09%09    %09%09t
@@ -1957,18 +1957,16 @@
 %09%09try %7B%0A
-//
 %09%09%09%09%09   
@@ -2010,18 +2010,16 @@
 g again%0A
-//
 %09%09%09%09%09%09%09%09
@@ -2039,18 +2039,16 @@
 (5000);%0A
-//
 %09%09%09%09%09%09%09%09
@@ -2083,18 +2083,16 @@
 n e1) %7B%0A
-//
 %09%09%09%09%09%09%09%09
@@ -2114,18 +2114,16 @@
 race();%0A
-//
 %09%09%09%09%09%09%09%09
@@ -2145,18 +2145,16 @@
 %09%09%09    %09
-//
 %7D%0A%09%09%09%09  
@@ -2153,24 +2153,26 @@
 %7D%0A%09%09%09%09    %09%0A
+%0A%09
 %09%09%09%09    %09Sys
@@ -2227,26 +2227,8 @@
 t);%0A
-%09%09%09%09    %09%0A%09%09    %09%0A
 %09%09%09%09
@@ -2633,16 +2633,179 @@
 on();%0A%09%09
+c.setRequestProperty(%22User-Agent%22, %22Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2%22);%0A%09%09c.setConnectTimeout(5000);
 %0A%09%09c.con

set timeout, agent and more trys