Issue
I have a Flask app running via Google Cloud Run and I need to know the user's IP-Address. I am using gunicorn as my Server. I have tried the following code:
request.remote_addr
request.environ['REMOTE_ADDR']
request.environ.get('HTTP_X_REAL_IP', request.remote_addr)
It is returning this IP-Address: 169.254.8.129
which is not mine.
Is this maybe the IP of a Load-Balancer between the app and the user?
And is there a way to get the correct IP-Address without having to use additional Services?
Solution
You have headers provided by Google. In my tests I got these 2:
X-Forwarded-For: [MyPubliCIp, LoadBalancerIp,MyPubliCIp]
Forwarded: [for="MyPubliCIp";proto=http]
Use them as you want.
Answered By - guillaume blaquiere
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.