Advertisement
dereksir

Untitled

May 11th, 2023 (edited)
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import fetch from 'node-fetch';
  2. import { HttpsProxyAgent } from 'https-proxy-agent';
  3.  
  4. const proxyList = [
  5.   { host: '103.69.108.78', port: 8191 },
  6.   { host: '61.29.96.146', port: 80 },
  7.   { host: '154.204.58.155', port: 8090 },
  8. ];
  9.  
  10. async function RotateProxy(proxyList, targetUrl) {
  11.   for (const proxy of proxyList) {
  12.     try {
  13.       //construct proxy URL  
  14.       const proxyUrl = `http://${proxy.host}:${proxy.port}`;
  15.       //create proxy agent  
  16.       const proxyAgent = new HttpsProxyAgent(proxyUrl);
  17.  
  18.       //make request using random proxy from array  
  19.       const response = await fetch(targetUrl, { agent: proxyAgent });
  20.       const html = await response.text();
  21.  
  22.       console.log(html);
  23.     } catch (error) {
  24.       console.error(error);
  25.     }
  26.   }
  27. }
  28.  
  29. const targetUrl = 'https://ident.me/ip';
  30. await RotateProxy(proxyList, targetUrl);
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement