File size: 1,051 Bytes
453e604
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import subprocess
import sys

# Step 1: Ensure fastapi and uvicorn are installed
def install_dependencies():
    subprocess.run([sys.executable, "-m", "pip", "install", "--upgrade", "fastapi", "uvicorn", "httpx"], check=True)

try:
    import fastapi
    import uvicorn
    import httpx
except ImportError:
    install_dependencies()
    import fastapi
    import uvicorn
    import httpx

from fastapi import FastAPI, Response
from fastapi.responses import PlainTextResponse

app = FastAPI()

# Step 2: Define endpoint to proxy ips.txt from port 5000
@app.get("/ips.txt", response_class=PlainTextResponse)
async def get_ips():
    url = "http://207.180.209.185:5000/ips.txt"
    try:
        async with httpx.AsyncClient(timeout=5.0) as client:
            response = await client.get(url)
            response.raise_for_status()
            return Response(content=response.text, media_type="text/plain")
    except httpx.RequestError as e:
        return Response(content=f"Error fetching data: {str(e)}", media_type="text/plain", status_code=500)