README.md:
title: Http
emoji: 🚀
colorFrom: pink
colorTo: yellow
sdk: docker
pinned: false
Dockerfile:
FROM python:3.9
WORKDIR /code
COPY ./requirements.txt /code/requirements.txt
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
COPY . .
CMD ["flask", "run", "--host", "0.0.0.0", "--port", "7860"]
app.py:
from flask import Flask, render_template
import requests
import time
from apscheduler.schedulers.background import BackgroundScheduler
from concurrent.futures import ThreadPoolExecutor, as_completed
app = Flask(__name__)
# Global list to store working proxies with geolocation data
working_proxies = []
# Function to get the country for a given IP
def get_country(ip):
try:
response = requests.get(f"http://ip-api.com/json/{ip}")
data = response.json()
return data.get("country", "Unknown")
except Exception:
return "Unknown"
# Function to check if a proxy is working and fetch its country
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) # Reduced timeout to 1 second
if response.status_code == 200:
elapsed_time = time.perf_counter() - start_time
ip = proxy.split(':')[0]
country = get_country(ip)
return proxy, elapsed_time, country
except Exception:
return None
# Function to fetch and validate proxies
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=200) 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)
# Sort proxies by response time and update the global list
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}")
# Schedule the proxy fetching every 10 minutes (can be adjusted as needed)
scheduler = BackgroundScheduler()
scheduler.add_job(func=fetch_and_check_proxies, trigger="interval", minutes=10)
scheduler.start()
# Route to display the working proxies
@app.route('/')
def home():
return render_template('index.html', proxies=working_proxies)
if __name__ == "__main__":
app.run(host='0.0.0.0', port=5000)
requirements.txt:
Flask==2.3.3
requests==2.31.0
uvicorn
Flask-APScheduler
templates/index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Working Proxies</title>
<style>
/* Global base styles */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
/* Background style */
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
color: #ffffff;
background: linear-gradient(135deg, #e74c3c, #c0392b);
position: relative;
min-height: 100vh;
overflow-x: hidden;
}
/* Overlay gradient with animated shine effect */
body::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100vh;
background: rgba(255, 255, 255, 0.1);
transform: translateX(-50%) translateY(-50%) rotate(-45deg);
animation: shine 4s infinite linear;
pointer-events: none;
z-index: 0;
}
@keyframes shine {
0% { transform: translateX(-50%) translateY(-50%) rotate(-45deg); }
100% { transform: translateX(50%) translateY(50%) rotate(-45deg); }
}
/* Transparent content container centered on page with fade-in animation */
.container {
background-color: rgba(0, 0, 0, 0.6);
padding: 20px;
border-radius: 8px;
max-width: 800px;
padding-top: 50px;
margin: 0 auto;
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.3);
text-align: center;
animation: fadeInUp 1s ease-in-out;
position: relative;
z-index: 1;
}
/* Header styles */
h1 {
font-size: 2.5em;
margin-bottom: 10px;
color: #f1f1f1;
}
/* Paragraph styles */
p {
font-size: 1.2em;
margin-bottom: 20px;
color: #f1f1f1;
}
/* Table styling */
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
th, td {
padding: 12px;
text-align: left;
border: 1px solid #444;
transition: transform 0.3s ease, box-shadow 0.3s ease;
}
th {
background-color: rgba(0, 123, 255, 0.8);
color: #ffffff;
}
td {
background-color: rgba(255, 255, 255, 0.1);
color: #e6e6e6;
}
/* Row hover effect: scaling and shadow */
tr:hover td {
background-color: rgba(0, 123, 255, 0.2);
transform: scale(1.05);
box-shadow: 0px 4px 12px rgba(0, 123, 255, 0.4);
}
/* Fade-in animation */
@keyframes fadeInUp {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
</style>
</head>
<body>
<div class="container">
<h1>Working Proxies</h1>
<p>Total Proxies Found: {{ proxies | length }}</p>
<table>
<thead>
<tr>
<th>Proxy Address</th>
<th>Response Time (seconds)</th>
<th>Country</th>
</tr>
</thead>
<tbody>
{% for proxy, response_time, country in proxies %}
<tr>
<td>{{ proxy }}</td>
<td>{{ response_time }}</td>
<td>{{ country }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</body>
</html>
使用方法:1.代理软件2.浏览器插件3.指纹浏览器(推荐用来注册一些服务还是不错的)