Upload 4 files
Browse files- Dockerfile +16 -0
- README.md +4 -4
- app.py +55 -0
- requirements.txt +4 -0
Dockerfile
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
|
2 |
+
# you will also find guides on how best to write your Dockerfile
|
3 |
+
|
4 |
+
FROM python:3.9
|
5 |
+
|
6 |
+
RUN useradd -m -u 1000 user
|
7 |
+
|
8 |
+
WORKDIR /app
|
9 |
+
|
10 |
+
COPY --chown=user ./requirements.txt requirements.txt
|
11 |
+
|
12 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
13 |
+
|
14 |
+
COPY --chown=user . /app
|
15 |
+
|
16 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: docker
|
7 |
pinned: false
|
8 |
---
|
|
|
1 |
---
|
2 |
+
title: Proxy
|
3 |
+
emoji: π
|
4 |
+
colorFrom: green
|
5 |
+
colorTo: green
|
6 |
sdk: docker
|
7 |
pinned: false
|
8 |
---
|
app.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, request, jsonify
|
2 |
+
import requests
|
3 |
+
import threading
|
4 |
+
import time
|
5 |
+
|
6 |
+
app = Flask(__name__)
|
7 |
+
|
8 |
+
def test_proxy(proxy):
|
9 |
+
try:
|
10 |
+
start_time = time.time()
|
11 |
+
response = requests.get('http://httpbin.org/ip', proxies={'http': proxy, 'https': proxy}, timeout=5)
|
12 |
+
end_time = time.time()
|
13 |
+
return {
|
14 |
+
'proxy': proxy,
|
15 |
+
'working': response.status_code == 200,
|
16 |
+
'time': round((end_time - start_time) * 1000, 2)
|
17 |
+
}
|
18 |
+
except:
|
19 |
+
return {
|
20 |
+
'proxy': proxy,
|
21 |
+
'working': False,
|
22 |
+
'time': None
|
23 |
+
}
|
24 |
+
|
25 |
+
def test_proxies_threaded(proxies):
|
26 |
+
results = []
|
27 |
+
threads = []
|
28 |
+
|
29 |
+
def worker(proxy):
|
30 |
+
result = test_proxy(proxy)
|
31 |
+
results.append(result)
|
32 |
+
|
33 |
+
for proxy in proxies:
|
34 |
+
thread = threading.Thread(target=worker, args=(proxy,))
|
35 |
+
threads.append(thread)
|
36 |
+
thread.start()
|
37 |
+
|
38 |
+
for thread in threads:
|
39 |
+
thread.join()
|
40 |
+
|
41 |
+
return results
|
42 |
+
|
43 |
+
@app.route('/test-proxies', methods=['POST'])
|
44 |
+
def test_proxies():
|
45 |
+
data = request.json
|
46 |
+
proxies = data.get('proxies', [])
|
47 |
+
|
48 |
+
if not proxies:
|
49 |
+
return jsonify({'error': 'No proxies provided'}), 400
|
50 |
+
|
51 |
+
results = test_proxies_threaded(proxies)
|
52 |
+
return jsonify(results)
|
53 |
+
|
54 |
+
if __name__ == '__main__':
|
55 |
+
app.run(debug=True)
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
fastapi
|
2 |
+
uvicorn
|
3 |
+
aiohttp
|
4 |
+
webscout
|