SHARE
TWEET

Request

a guest Aug 23rd, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.*;
  2. import java.net.HttpURLConnection;
  3. import java.net.InetSocketAddress;
  4. import java.net.Proxy;
  5. import java.net.URL;
  6. import java.util.*;
  7.  
  8. public class Request implements Runnable{
  9.     private String url;
  10.     private String host;
  11.     private int port;
  12.     public static volatile boolean result = false;
  13.    
  14.     public static ArrayList<ProxyService> worked = new ArrayList<>();
  15.    
  16.     public Request(String host , int port , String url) {
  17.         this.host = host;
  18.         this.port = port;
  19.         this.url = url;
  20.     }
  21.    
  22.     @Override
  23.     public void run() {
  24.         Proxy proxy = new Proxy(Proxy.Type.HTTP , new InetSocketAddress(host ,port));
  25.         try {
  26.             HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(proxy);
  27.             connection.setReadTimeout(2000);
  28.             connection.setConnectTimeout(2000);
  29.             connection.setRequestMethod("GET");
  30.             connection.connect();
  31.            
  32.             if (HttpURLConnection.HTTP_OK == connection.getResponseCode()) {
  33.                 System.out.println("Соединение установлено , прокси работает ");
  34.                 result = true;
  35.             }
  36.         }
  37.        
  38.         catch (IOException e) {
  39.             System.out.println("Соединение не установлено , прокси не работает");
  40.             result = false;
  41.         }
  42.        
  43.         if (result) {
  44.             worked.add(new ProxyService(host , port));
  45.             try {
  46.                 PrintStream ps = new PrintStream("C:\\Users\\samsung\\Desktop\\a.txt");
  47.                 for (ProxyService p : worked) {
  48.                     String host = p.getHost();
  49.                     int port = p.getPort();
  50.                     ps.println(p.getHost() + ":" + p.getPort());
  51.                 }
  52.                 ps.close();
  53.             }
  54.            
  55.             catch (IOException e) {
  56.                 e.printStackTrace();
  57.             }
  58.         }
  59.     }
  60. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top