rendered paste bodyimport java.io.*;
import java.net.*;
import java.util.LinkedList;
public class ProxyTester {
public static void main(String[] args) throws IOException {
try {
outputList(tryProxies(getList(args[0])), args[1]);
} catch(IOException e) {
System.out.print("IOException: "+e.toString());
}
}
private static LinkedList<String> getList(String inputFilename) throws IOException {
LinkedList<String> list = new LinkedList<String>();
BufferedReader stdIn = new BufferedReader(new FileReader(inputFilename));
String inputProxies;
while ((inputProxies = stdIn.readLine()) != null) {
list.add(inputProxies);
}
stdIn.close();
return list;
}
private static LinkedList<String> tryProxies(LinkedList<String> inputProxies) throws IOException {
LinkedList<String> workingProxies = new LinkedList<String>();
for(String currentProxy : inputProxies) {
String tmp[] = currentProxy.split(":");
if(connect(tmp[0], Integer.parseInt(tmp[1]))) {
workingProxies.add(currentProxy);
}
}
return workingProxies;
}
private static void outputList(LinkedList<String> workingProxies, String outputFilename) throws IOException {
BufferedWriter out = new BufferedWriter(new FileWriter(outputFilename));
for(String currentProxy : workingProxies) {
out.write(currentProxy+"\n");
}
out.close();
}
private static boolean connect(String proxy, int port) throws IOException {
Socket proxySocket = new Socket(proxy, port);
PrintWriter out = new PrintWriter(proxySocket.getOutputStream(), true);
BufferedReader in = new BufferedReader(new InputStreamReader(
proxySocket.getInputStream()));
out.println("GET http://u1.swirve.com/");
while(in != null) {
if(in.equals("HTTP/1.1 OK")) {
out.close();
in.close();
proxySocket.close();
return true;
}
}
out.close();
in.close();
proxySocket.close();
return false;
}
}