Guest User

Untitled

a guest
Feb 14th, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. import requests
  2. from multiprocessing import Pool, Process
  3.  
  4. def load_proxies(path='s'):
  5.     with open(path, 'r') as f:
  6.         return list(map(lambda s: s.strip('\n'), f.readlines()))
  7.  
  8. def ping(proxy: str):
  9.     proxies = {
  10.         "http": f'http://{proxy}',
  11.         "https": f'https://{proxy}'
  12.     }
  13.     try:
  14.         connected = requests.get(
  15.             "https://google.com", proxies=proxies, timeout=1
  16.         ).status_code == 200
  17.         print(f"Proxy [ {proxy} ] available: {connected}")
  18.     except requests.exceptions.ConnectionError as e:
  19.         print(f"Proxy [ {proxy} ] is unvailable")
  20.  
  21. if __name__ == "__main__":
  22.     proxies = load_proxies()
  23.     p = Pool(5)
  24.     for proxy in proxies:
  25.         Process(target=ping, args=(proxy, )).start()
Advertisement
Add Comment
Please, Sign In to add comment