Write me python proxy checker
- User
Write me python proxy checker
- Assistant
Certainly! Here's a Python script that checks if a list of proxies are working by attempting to make a request to a specified URL:
import requests from concurrent.futures import ThreadPoolExecutor, as_completed def check_proxy(proxy): try: response = requests.get('http://example.com', proxies={'http': proxy, 'https': proxy}, timeout=5) if response.status_code == 200: return proxy except: pass return None def main(): proxies = [ 'http://proxy1:port', 'http://proxy2:port', 'http://proxy3:port', # Add more proxies here ] working_proxies = [] with ThreadPoolExecutor() as executor: futures = [executor.submit(check_proxy, proxy) for proxy in proxies] for future in as_completed(futures): result = future.result() if result: working_proxies.append(result) print("Working proxies:") for proxy in working_proxies: print(proxy) if __name__ == '__main__': main()This script does the following:
-
We define a function called
check_proxythat takes a proxy as input. It tries to make a GET request to a specified URL ('http://example.com'in this case) using the provided proxy. If the request is successful (status code 200), it returns the proxy. Otherwise, it returnsNone. -
In the
mainfunction, we define a list of proxies that we want to check. You can add your own proxies to this list. -
We create an empty list called
working_proxiesto store the proxies that are found to be working. -
We use
ThreadPoolExecutorto create a thread pool and submit thecheck_proxyfunction for each proxy in theproxieslist. This allows us to check multiple proxies concurrently. -
We iterate over the completed futures using
as_completedand retrieve the result of each future. If the result is notNone, it means the proxy is working, and we append it to theworking_proxieslist. -
Finally, we print the list of working proxies.
Note: Make sure to replace
'http://example.com'with the URL you want to use for testing the proxies. Also, replace the placeholder proxies in theproxieslist with the actual proxies you want to check.This script uses the
requestslibrary to make HTTP requests and theconcurrent.futuresmodule to handle concurrent execution of the proxy checks. You may need to install therequestslibrary if you haven't already done so. You can install it using . -
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.