Advertisement
Guest User

Untitled

a guest
Feb 6th, 2022
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. import asyncio
  2.  
  3. from aiohttp import ClientSession
  4.  
  5.  
  6. with open('working-proxies-history.txt') as f:
  7.     proxy_list = [f'http://{proxy}' for proxy in f.read().split()]
  8.  
  9.  
  10. async def fetch(proxy: str):
  11.     async with ClientSession() as s:
  12.         try:
  13.             async with s.get('http://icanhazip.com', proxy=proxy, timeout=6) as r:
  14.                 await r.text()
  15.         except:
  16.             return False
  17.         else:
  18.             return True
  19.  
  20.  
  21. async def main():
  22.     step = 400
  23.  
  24.     count = 0
  25.     for i in range(0, len(proxy_list), step):
  26.         tasks = [
  27.             fetch(proxy)
  28.             for proxy in proxy_list[i:i + step]
  29.         ]
  30.  
  31.         result = await asyncio.gather(*tasks)
  32.         count += result.count(True)
  33.  
  34.     print(count)
  35.  
  36.  
  37. asyncio.run(main())
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement