NetwortTools / app.py
tuhbooh's picture
Update app.py
24d4349 verified
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)