File size: 1,318 Bytes
8b4dc08
db919cd
25d562a
db919cd
 
 
8b4dc08
 
db919cd
25d562a
db919cd
8b4dc08
24d4349
 
 
 
 
bccdc0c
24d4349
 
 
bccdc0c
8b4dc08
24d4349
 
bccdc0c
24d4349
bccdc0c
25d562a
24d4349
db919cd
 
 
bccdc0c
db919cd
25d562a
bccdc0c
db919cd
25d562a
db919cd
 
25d562a
 
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
from fastapi import FastAPI, Request, HTTPException
import time
import uvicorn

app = FastAPI()

last_request_time = {}

@app.get("/")
async def root(request: Request):
    headers = request.headers
    
    # 1. Lấy Client IP
    forwarded = headers.get("x-forwarded-for")
    client_ip = forwarded.split(",")[0] if forwarded else "unknown"

    # 2. Rate Limiting (0.5s)
    now = time.time()
    if client_ip in last_request_time:
        if now - last_request_time[client_ip] < 0.5:
            raise HTTPException(status_code=429, detail="Slow down!")
    last_request_time[client_ip] = now

    # 3. Lấy vị trí từ Header
    city = headers.get("cf-ipcity", "Unknown City")
    country = headers.get("cf-ipcountry", "VN")
    real_loc = f"{city}, {country}"

    return {
        "info": "This is a high-performance Network Discovery Tool designed to provide real-time connection insights and geolocation data. Made by MinhDuc with love",
        "fl": "998f87",
        "h": headers.get("host", "huggingface.co"),
        "ip": client_ip,
        "ts": now,
        "visit_scheme": "https",
        "uag": headers.get("user-agent", "unknown"),
        "loc": real_loc,
        "tls": "TLSv1.3",
        "status": "active"
    }

if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=7860)