Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.net.HttpURLConnection;
- import java.net.InetSocketAddress;
- import java.net.Proxy;
- import java.net.URL;
- import java.util.*;
- public class Request implements Runnable{
- private String url;
- private String host;
- private int port;
- public static volatile boolean result = false;
- public static ArrayList<ProxyService> worked = new ArrayList<>();
- public Request(String host , int port , String url) {
- this.host = host;
- this.port = port;
- this.url = url;
- }
- @Override
- public void run() {
- Proxy proxy = new Proxy(Proxy.Type.HTTP , new InetSocketAddress(host ,port));
- try {
- HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(proxy);
- connection.setReadTimeout(2000);
- connection.setConnectTimeout(2000);
- connection.setRequestMethod("GET");
- connection.connect();
- if (HttpURLConnection.HTTP_OK == connection.getResponseCode()) {
- System.out.println("Соединение установлено , прокси работает ");
- result = true;
- }
- }
- catch (IOException e) {
- System.out.println("Соединение не установлено , прокси не работает");
- result = false;
- }
- if (result) {
- worked.add(new ProxyService(host , port));
- try {
- PrintStream ps = new PrintStream("C:\\Users\\samsung\\Desktop\\a.txt");
- for (ProxyService p : worked) {
- String host = p.getHost();
- int port = p.getPort();
- ps.println(p.getHost() + ":" + p.getPort());
- }
- ps.close();
- }
- catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement