Python 在 AWS 上获取远程 IP 地址

Python On AWS Get Remote IP Address

我在 AWS Elastic Beanstalk 上有一个 Python/Flask 应用 运行。

我需要在 Python 脚本被触发时获取用户的远程 IP 地址,但是在 python 脚本中使用 request.environ['REMOTE_ADDR'] 是'工作。它返回的似乎是我的服务器的私有 IP 地址,而不是用户的 IP 地址。

http://xxxxxx-env.eu-west-2.elasticbeanstalk.com/xxx

xxx 解析为我的 Python 应用包含:

if ('REMOTE_ADDR' in request.headers):
    print (request.environ['REMOTE_ADDR'])

但结果是: 172.31.xx.xxx

当我的实际IP是:

83.164.xx.xxx

任何人都可以指出如何获取用户的远程 IP 的正确方向吗?

我设法解决了这个问题。 Elastic Beanstalk 自动传递远程 IP 地址,可以按如下方式检索:

if (request.access_route):
    #return remote ip
    remoteIP = request.access_route[0]
    #return full ip list (if more than one passed through)
    remoteIPRaw = request.access_route