Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // import the required modules
- import got from 'got';
- import {HttpsProxyAgent} from 'hpagent';
- // define a list of proxy URLs
- const proxyList = [
- 'http://20.219.180.149:3129',
- 'http://198.199.70.20:31028',
- 'http://8.219.97.248:80',
- // add more proxy URLs as needed
- ];
- // function to select a random proxy from the list
- function getRandomProxy() {
- const randomIndex = Math.floor(Math.random() * proxyList.length);
- return proxyList[randomIndex];
- }
- const proxyOptions = {
- agent: {
- // create a new HttpsProxyAgent instance
- https: new HttpsProxyAgent({
- // add proxy settings
- keepAlive: true,
- keepAliveMsecs: 1000,
- maxSockets: 256,
- maxFreeSockets: 256,
- scheduling: 'lifo',
- // specify proxy URL.
- proxy: getRandomProxy()
- })
- }
- };
- try {
- // make HTTP request
- const {body} = await got('https://httpbin.io/ip', proxyOptions);
- // log the response
- console.log(body);
- } catch (error) {
- console.error(error);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement