File size: 2,247 Bytes
3645ba1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3f0ba13
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import httpx
from fastapi import FastAPI, Query
from fastapi.responses import PlainTextResponse

app = FastAPI(
    title="Torpedo Proxy Generator",
    description="Generates IP:PORT lists specifically for Traffic Generators."
)

# This is the upstream source that allows country filtering for free
BASE_URL = "https://api.proxyscrape.com/v2/"

@app.get("/", response_class=PlainTextResponse)
def home():
    return "Status: Online. Use /get?country=US&protocol=http to get proxies."

@app.get("/get", response_class=PlainTextResponse)
async def get_proxies(
    country: str = Query("all", description="2-letter Country Code (e.g., US, DE, FR) or 'all'"),
    protocol: str = Query("http", description="http, socks4, or socks5"),
    timeout: int = Query(10000, description="Timeout in ms (lower is faster proxies but fewer results)")
):
    """
    Fetches proxies and returns them in PLAIN TEXT format (IP:PORT)
    perfect for Torpedo Traffic Generator.
    """
    
    # Normalize input
    country = country.lower()
    protocol = protocol.lower()
    
    # Construct the query to the upstream provider
    api_url = f"{BASE_URL}?request=getproxies&protocol={protocol}&timeout={timeout}&country={country}&ssl=all&anonymity=all"
    
    async with httpx.AsyncClient() as client:
        try:
            response = await client.get(api_url, timeout=15)
            if response.status_code == 200:
                # The upstream API returns text properly, we pass it through
                data = response.text.strip()
                
                # Validation: If provider returns empty or error
                if not data:
                    return f"No proxies found for country: {country.upper()}"
                
                return data
            else:
                return "Error fetching from upstream source."
        except Exception as e:
            return f"Server Error: {str(e)}"

@app.get("/countries", response_class=PlainTextResponse)
def list_common_countries():
    """Helper to show codes for Torpedo users"""
    return """
Common Country Codes:
US = United States
DE = Germany
FR = France
GB = United Kingdom
BR = Brazil
IN = India
RU = Russia
CN = China
CA = Canada
AU = Australia
ALL = All Countries