ip-test / app.py
bcci's picture
Update app.py
a81ba94 verified
raw
history blame contribute delete
542 Bytes
from fastapi import FastAPI, Request
app = FastAPI()
@app.get("/")
async def get_ip(request: Request):
client_host = request.client.host
print(request.headers)
# Handle proxy headers if present
forwarded_for = request.headers.get("x-forwarded-for")
if forwarded_for:
forwarded_string = forwarded_for.split(",")
for i in forwarded_string:
client_host = i
return {"ip_address": client_host}
import uvicorn
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=7860)