|
from flask import Flask, render_template
|
|
import requests
|
|
import time
|
|
from apscheduler.schedulers.background import BackgroundScheduler
|
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
from datetime import datetime
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
working_proxies = []
|
|
|
|
|
|
def check_proxy(proxy):
|
|
start_time = time.perf_counter()
|
|
try:
|
|
with requests.Session() as session:
|
|
response = session.head("https://www.google.com/", proxies={'http': proxy, 'https': proxy}, timeout=1)
|
|
if response.status_code == 200:
|
|
elapsed_time = time.perf_counter() - start_time
|
|
return proxy, elapsed_time
|
|
except Exception:
|
|
return None
|
|
|
|
|
|
def fetch_and_check_proxies():
|
|
global working_proxies
|
|
try:
|
|
print("Fetching proxies...")
|
|
resp = requests.get("https://api.proxyscrape.com/v2/?request=displayproxies&protocol=http&timeout=10000&country=all&ssl=all&anonymity=all")
|
|
proxies = [proxy.strip() for proxy in resp.text.strip().split("\n") if proxy.strip()]
|
|
|
|
print(f"Found {len(proxies)} proxies. Checking their validity...")
|
|
|
|
temp_working_proxies = []
|
|
with ThreadPoolExecutor(max_workers=300) as executor:
|
|
futures = {executor.submit(check_proxy, proxy): proxy for proxy in proxies}
|
|
|
|
for future in as_completed(futures):
|
|
result = future.result()
|
|
if result:
|
|
temp_working_proxies.append(result)
|
|
|
|
|
|
temp_working_proxies.sort(key=lambda x: x[1])
|
|
working_proxies = temp_working_proxies
|
|
|
|
print(f"Found {len(working_proxies)} working proxies.")
|
|
|
|
except Exception as e:
|
|
print(f"Error occurred: {e}")
|
|
|
|
|
|
scheduler = BackgroundScheduler()
|
|
scheduler.add_job(func=fetch_and_check_proxies, trigger="interval", minutes=0.1)
|
|
scheduler.start()
|
|
|
|
|
|
@app.route('/')
|
|
def home():
|
|
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
return render_template('index.html', proxies=working_proxies, last_updated=now)
|
|
|
|
if __name__ == "__main__":
|
|
app.run(host='0.0.0.0', port=5000) |