File size: 1,320 Bytes
b145a5f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
from flask import Flask, request, jsonify
import requests
import threading
import time
app = Flask(__name__)
def test_proxy(proxy):
try:
start_time = time.time()
response = requests.get('http://httpbin.org/ip', proxies={'http': proxy, 'https': proxy}, timeout=5)
end_time = time.time()
return {
'proxy': proxy,
'working': response.status_code == 200,
'time': round((end_time - start_time) * 1000, 2)
}
except:
return {
'proxy': proxy,
'working': False,
'time': None
}
def test_proxies_threaded(proxies):
results = []
threads = []
def worker(proxy):
result = test_proxy(proxy)
results.append(result)
for proxy in proxies:
thread = threading.Thread(target=worker, args=(proxy,))
threads.append(thread)
thread.start()
for thread in threads:
thread.join()
return results
@app.route('/test-proxies', methods=['POST'])
def test_proxies():
data = request.json
proxies = data.get('proxies', [])
if not proxies:
return jsonify({'error': 'No proxies provided'}), 400
results = test_proxies_threaded(proxies)
return jsonify(results)
if __name__ == '__main__':
app.run(debug=True)
|