[英]Python On AWS Get Remote IP Address
我有一個在AWS Elastic Beanstalk上運行的Python / Flask應用程序。
我需要獲取用戶的遠程IP地址,因為Python腳本已觸發,但是在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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.