Advertisement
dereksir

Untitled

Mar 19th, 2024 (edited)
917
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.63 KB | None | 0 0
  1. package com.example;
  2.  
  3. // import the required classes
  4. import com.gargoylesoftware.htmlunit.BrowserVersion;
  5. import com.gargoylesoftware.htmlunit.Page;
  6. import com.gargoylesoftware.htmlunit.WebClient;
  7.  
  8. import java.util.ArrayList;
  9. import java.util.List;
  10. import java.util.Random;
  11.  
  12. public class Main {
  13.     public static void main(String[] args) {
  14.         // define your proxy list
  15.         List<String> proxyList = new ArrayList<>();
  16.         proxyList.add("129.80.134.71:3128");
  17.         proxyList.add("185.49.170.20:43626");
  18.         proxyList.add("14.177.236.212:55443");
  19.  
  20.         // create a random number generator
  21.         Random random = new Random();
  22.         // generate a random index to select a proxy from the list
  23.         int randomIndex = random.nextInt(proxyList.size());
  24.         // select random proxy
  25.         String randomProxy = proxyList.get(randomIndex);
  26.  
  27.         // extract proxy host and port based on the random index
  28.         String PROXY_HOST = randomProxy.split(":")[0];
  29.         int PROXY_PORT = Integer.parseInt(randomProxy.split(":")[1]);
  30.  
  31.         // create Chrome Web Client instance using specified proxy settings.
  32.         try (final WebClient webClient = new WebClient(BrowserVersion.CHROME, PROXY_HOST, PROXY_PORT))  {
  33.  
  34.             // navigate to target web page
  35.             Page page = webClient.getPage("https://httpbin.io/ip");
  36.  
  37.             // extract the content as string
  38.             String pageContent = page.getWebResponse().getContentAsString();
  39.  
  40.             // print the content
  41.             System.out.println(pageContent);
  42.         } catch (Exception e) {
  43.             e.printStackTrace();
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement