backend / app.py
Abhaykoul's picture
Upload 4 files
b145a5f verified
raw
history blame
1.32 kB
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)