File size: 542 Bytes
c11bb6b
 
 
 
 
 
 
 
b1f9aaf
f57a032
c11bb6b
 
 
a81ba94
 
 
c11bb6b
 
3626605
 
 
 
168c30a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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)