【问题标题】:Python On AWS Get Remote IP AddressAWS 上的 Python 获取远程 IP 地址
【发布时间】:2018-03-14 12:36:09
【问题描述】:

我有一个在 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 的正确方向吗?

【问题讨论】:

    标签: javascript python flask ip-address


    【解决方案1】:

    我设法解决了这个问题。 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-22
      • 2020-11-29
      • 2012-03-01
      • 2018-10-11
      • 2011-06-13
      • 1970-01-01
      • 2011-11-12
      • 1970-01-01
      相关资源
      最近更新 更多