Advertisement
dereksir

Untitled

Apr 21st, 2024 (edited)
1,288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // import the required modules
  2. import got from 'got';
  3. import {HttpsProxyAgent} from 'hpagent';
  4.  
  5. // define a list of proxy URLs
  6. const proxyList = [
  7.   'http://20.219.180.149:3129',
  8.   'http://198.199.70.20:31028',
  9.   'http://8.219.97.248:80',
  10.   // add more proxy URLs as needed
  11. ];
  12.  
  13. // function to select a random proxy from the list
  14. function getRandomProxy() {
  15.   const randomIndex = Math.floor(Math.random() * proxyList.length);
  16.   return proxyList[randomIndex];
  17. }
  18.  
  19. const proxyOptions = {
  20.     agent: {
  21.         // create a new HttpsProxyAgent instance
  22.         https: new HttpsProxyAgent({
  23.             // add proxy settings
  24.             keepAlive: true,
  25.             keepAliveMsecs: 1000,
  26.             maxSockets: 256,
  27.             maxFreeSockets: 256,
  28.             scheduling: 'lifo',
  29.             // specify proxy URL.
  30.             proxy: getRandomProxy()
  31.         })
  32.     }
  33. };
  34.  
  35. try {
  36.     // make HTTP request
  37.     const {body} = await got('https://httpbin.io/ip', proxyOptions);
  38.     // log the response
  39.     console.log(body);
  40. } catch (error) {
  41.     console.error(error);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement