Advertisement
Guest User

Untitled

a guest
May 25th, 2015
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.12 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.BufferedWriter;
  3. import java.io.FileInputStream;
  4. import java.io.FileOutputStream;
  5. import java.io.InputStreamReader;
  6. import java.io.OutputStreamWriter;
  7. import java.net.InetSocketAddress;
  8. import java.net.Proxy;
  9. import java.net.SocketAddress;
  10. import java.net.URL;
  11. import java.net.URLConnection;
  12.  
  13. public class ProxyTest {
  14.  
  15.     public static void main(String[] args) {
  16.         FileInputStream fStream = null;
  17.         InputStreamReader isr = null;
  18.         BufferedReader br = null;
  19.         try {
  20.             fStream = new FileInputStream(
  21.                     "C:\\Users\\Vlad\\Desktop\\totest.txt");
  22.             isr = new InputStreamReader(fStream);
  23.             br = new BufferedReader(isr);
  24.             String row;
  25.             while ((row = br.readLine()) != null && row != "") {
  26.                 testProxy(row.split("\\t")[0],
  27.                         Integer.parseInt(row.split("\\t")[1]), true);
  28.                 testProxy(row.split("\\t")[0],
  29.                         Integer.parseInt(row.split("\\t")[1]), false);
  30.             }
  31.         } catch (Exception ee) {
  32.             ee.printStackTrace();
  33.         } finally {
  34.             if (br != null) {
  35.                 try {
  36.                     br.close();
  37.                 } catch (Exception e) {
  38.                 }
  39.             } else if (isr != null) {
  40.                 try {
  41.                     isr.close();
  42.                 } catch (Exception e) {
  43.                 }
  44.             } else if (fStream != null) {
  45.                 try {
  46.                     fStream.close();
  47.                 } catch (Exception e) {
  48.                 }
  49.             }
  50.         }
  51.     }
  52.  
  53.     public static void testProxy(String hostname, int port, boolean http) {
  54.         SocketAddress addr = new InetSocketAddress(hostname, port);
  55.         Proxy proxy;
  56.         if (http) {
  57.             proxy = new Proxy(Proxy.Type.HTTP, addr);
  58.         } else {
  59.             proxy = new Proxy(Proxy.Type.SOCKS, addr);
  60.         }
  61.         URL url;
  62.         InputStreamReader ir = null;
  63.         BufferedReader br = null;
  64.         try {
  65.             url = new URL("http://www.wimip.fr/");
  66.             URLConnection conn = url.openConnection(proxy);
  67.             ir = new InputStreamReader(conn.getInputStream());
  68.             br = new BufferedReader(ir);
  69.             String inputLine;
  70.             inputLine = br.readLine();
  71.             inputLine = br.readLine();
  72.             inputLine = br.readLine();
  73.             if (inputLine != null) {
  74.                 inputLine = inputLine.substring(7, inputLine.length() - 1);
  75.                 inputLine = inputLine.split(" ")[0] + " - " + hostname + ":"
  76.                         + port;
  77.                 if (http) {
  78.                     write("HTTP:" + inputLine);
  79.                 } else {
  80.                     write("SOCKS:" + inputLine);
  81.                 }
  82.             }
  83.         } catch (Exception e) {
  84.         } finally {
  85.             if (br != null) {
  86.                 try {
  87.                     br.close();
  88.                 } catch (Exception e) {
  89.                 }
  90.             } else if (ir != null) {
  91.                 try {
  92.                     ir.close();
  93.                 } catch (Exception e) {
  94.                 }
  95.             }
  96.         }
  97.     }
  98.  
  99.     public static void write(String s) {
  100.         FileOutputStream fStream = null;
  101.         OutputStreamWriter osw = null;
  102.         BufferedWriter bw = null;
  103.         try {
  104.             fStream = new FileOutputStream(
  105.                     "C:\\Users\\Vlad\\Desktop\\working.txt", true);
  106.             osw = new OutputStreamWriter(fStream);
  107.             bw = new BufferedWriter(osw);
  108.             bw.write(s);
  109.             bw.newLine();
  110.         } catch (Exception e) {
  111.         } finally {
  112.             if (bw != null) {
  113.                 try {
  114.                     bw.close();
  115.                 } catch (Exception e) {
  116.                 }
  117.             } else if (osw != null) {
  118.                 try {
  119.                     osw.close();
  120.                 } catch (Exception e) {
  121.                 }
  122.             } else if (fStream != null) {
  123.                 try {
  124.                     fStream.close();
  125.                 } catch (Exception e) {
  126.                 }
  127.             }
  128.         }
  129.     }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement