Spaces:
Paused
Paused
Create main.py
Browse files
main.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import httpx
|
| 2 |
+
from fastapi import FastAPI, Query
|
| 3 |
+
from fastapi.responses import PlainTextResponse
|
| 4 |
+
|
| 5 |
+
app = FastAPI(
|
| 6 |
+
title="Torpedo Proxy Generator",
|
| 7 |
+
description="Generates IP:PORT lists specifically for Traffic Generators."
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
# This is the upstream source that allows country filtering for free
|
| 11 |
+
BASE_URL = "https://api.proxyscrape.com/v2/"
|
| 12 |
+
|
| 13 |
+
@app.get("/", response_class=PlainTextResponse)
|
| 14 |
+
def home():
|
| 15 |
+
return "Status: Online. Use /get?country=US&protocol=http to get proxies."
|
| 16 |
+
|
| 17 |
+
@app.get("/get", response_class=PlainTextResponse)
|
| 18 |
+
async def get_proxies(
|
| 19 |
+
country: str = Query("all", description="2-letter Country Code (e.g., US, DE, FR) or 'all'"),
|
| 20 |
+
protocol: str = Query("http", description="http, socks4, or socks5"),
|
| 21 |
+
timeout: int = Query(10000, description="Timeout in ms (lower is faster proxies but fewer results)")
|
| 22 |
+
):
|
| 23 |
+
"""
|
| 24 |
+
Fetches proxies and returns them in PLAIN TEXT format (IP:PORT)
|
| 25 |
+
perfect for Torpedo Traffic Generator.
|
| 26 |
+
"""
|
| 27 |
+
|
| 28 |
+
# Normalize input
|
| 29 |
+
country = country.lower()
|
| 30 |
+
protocol = protocol.lower()
|
| 31 |
+
|
| 32 |
+
# Construct the query to the upstream provider
|
| 33 |
+
# We use ProxyScrape because your requested GitHub link did not have proxy data.
|
| 34 |
+
# ProxyScrape allows country filtering.
|
| 35 |
+
api_url = f"{BASE_URL}?request=getproxies&protocol={protocol}&timeout={timeout}&country={country}&ssl=all&anonymity=all"
|
| 36 |
+
|
| 37 |
+
async with httpx.AsyncClient() as client:
|
| 38 |
+
try:
|
| 39 |
+
response = await client.get(api_url, timeout=15)
|
| 40 |
+
if response.status_code == 200:
|
| 41 |
+
# The upstream API returns text properly, we pass it through
|
| 42 |
+
data = response.text.strip()
|
| 43 |
+
|
| 44 |
+
# Validation: If provider returns empty or error
|
| 45 |
+
if not data:
|
| 46 |
+
return f"No proxies found for country: {country.upper()}"
|
| 47 |
+
|
| 48 |
+
return data
|
| 49 |
+
else:
|
| 50 |
+
return "Error fetching from upstream source."
|
| 51 |
+
except Exception as e:
|
| 52 |
+
return f"Server Error: {str(e)}"
|
| 53 |
+
|
| 54 |
+
@app.get("/countries", response_class=PlainTextResponse)
|
| 55 |
+
def list_common_countries():
|
| 56 |
+
"""Helper to show codes for Torpedo users"""
|
| 57 |
+
return """
|
| 58 |
+
Common Country Codes:
|
| 59 |
+
US = United States
|
| 60 |
+
DE = Germany
|
| 61 |
+
FR = France
|
| 62 |
+
GB = United Kingdom
|
| 63 |
+
BR = Brazil
|
| 64 |
+
IN = India
|
| 65 |
+
RU = Russia
|
| 66 |
+
CN = China
|
| 67 |
+
CA = Canada
|
| 68 |
+
AU = Australia
|
| 69 |
+
ALL = All Countries
|