-1

I am trying to capture client ip in logs and getting correct ip on development server but after deployment on sit server, getting wrong ip by default (10.46.0.0). Please someone suggest, what else can be used in flask python? Thanks in advance.

Code:-

Import request

Ip = request.environ['REMOTE_ADDR']

AMC
  • 2,642
  • 7
  • 13
  • 35

2 Answers2

1

The IP address you retrieve is part of the CIDR block 10.0.0.0/8 and reserved for private networks. This tells me that your application deployed behind a reverse proxy which performs requests to your application on the original users' behalves. A reverse proxy would typically inform the upstream service (your application) about the originating IP address by adding the header X-Forwarded-For to the proxied request. This depends on the configuration of the reverse proxy, so you should contact the people in charge of the deployment server about its configuration.

oschlueter
  • 2,596
  • 1
  • 23
  • 46
0

It seems like you got the address from a Reverse Proxy. The original client IP may be forwarded as part of the proxy chain.

This worked for me.

client_ip = request.headers.get(
        'X-Forwarded-For',
        request.headers.get('Client-Ip',
            request.remote_addr))

There is a difference between WSGI and CGI.
WSGI: request.headers
CGI: request.environ

Detlef
  • 6,137
  • 2
  • 6
  • 24