Advertisement
Pandaaaa906

verify_socks5_proxy_in_awful_way

Nov 15th, 2020 (edited)
2,905
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. from concurrent.futures.thread import ThreadPoolExecutor
  2.  
  3. import requests
  4.  
  5.  
  6. def verify_proxy(proxy, test_url='https://www.google.com'):
  7.     host, port, *_ = proxy
  8.     try:
  9.         requests.get(test_url, proxies={
  10.             'http': f'socks5://{host}:{port}',
  11.             'https': f'socks5://{host}:{port}',
  12.         })
  13.     except BaseException as e:
  14.         return False
  15.     return True
  16.  
  17. def gen_proxies(fp):
  18.     with open(fp) as f:
  19.         for line in f:
  20.             if not line.strip():
  21.                 continue
  22.             yield line.strip().split(':')
  23.  
  24. if __name__ == '__main__':
  25.     candidates = tuple(gen_proxies('socks5'))
  26.     with ThreadPoolExecutor(max_workers=5) as executor:
  27.         for candidate, working in zip(candidates, executor.map(verify_proxy, candidates)):
  28.             if not working:
  29.                 continue
  30.             print(f'{candidate} is usable')
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement