Spaces:
Running
Running
Create server.py
Browse files
server.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import time
|
| 3 |
+
import requests
|
| 4 |
+
import subprocess
|
| 5 |
+
from threading import Thread
|
| 6 |
+
|
| 7 |
+
# URL de ton JSON/TXT GitHub
|
| 8 |
+
PROXY_TXT_RAW = "https://raw.githubusercontent.com/mishableskineetudiant-stack/proxylistfiltered/main/proxies_elite.txt"
|
| 9 |
+
|
| 10 |
+
# Fichier local utilisé par rotating-mitmproxy
|
| 11 |
+
LOCAL_PROXY_FILE = "/app/proxy_list.txt"
|
| 12 |
+
|
| 13 |
+
REFRESH_INTERVAL = 300 # 5 minutes
|
| 14 |
+
|
| 15 |
+
def update_proxy_file():
|
| 16 |
+
while True:
|
| 17 |
+
try:
|
| 18 |
+
print("[UPDATER] Fetching latest proxy list...")
|
| 19 |
+
r = requests.get(PROXY_TXT_RAW, timeout=10)
|
| 20 |
+
r.raise_for_status()
|
| 21 |
+
with open(LOCAL_PROXY_FILE, "w") as f:
|
| 22 |
+
f.write(r.text)
|
| 23 |
+
print(f"[UPDATER] Proxy list updated ({len(r.text.splitlines())} proxies)")
|
| 24 |
+
except Exception as e:
|
| 25 |
+
print(f"[UPDATER] Error updating proxies: {e}")
|
| 26 |
+
time.sleep(REFRESH_INTERVAL)
|
| 27 |
+
|
| 28 |
+
def start_rotating_proxy():
|
| 29 |
+
# Lancer rotating-mitmproxy en écoutant sur 3129
|
| 30 |
+
cmd = [
|
| 31 |
+
"python", "-m", "rotating_mitmproxy",
|
| 32 |
+
"--proxy-list", LOCAL_PROXY_FILE,
|
| 33 |
+
"--port", "3129",
|
| 34 |
+
"--strategy", "smart",
|
| 35 |
+
"--health-check"
|
| 36 |
+
]
|
| 37 |
+
print("[MAIN] Starting rotating-mitmproxy...")
|
| 38 |
+
subprocess.run(cmd)
|
| 39 |
+
|
| 40 |
+
if __name__ == "__main__":
|
| 41 |
+
# Thread qui met à jour le fichier toutes les 5 minutes
|
| 42 |
+
Thread(target=update_proxy_file, daemon=True).start()
|
| 43 |
+
|
| 44 |
+
# Démarre le serveur rotatif
|
| 45 |
+
start_rotating_proxy()
|
| 46 |
+
|