Created
June 7, 2017 20:42
-
-
Save ruanbekker/b745d6cb3bf56d4105f08b19eac6d8fc to your computer and use it in GitHub Desktop.
Python Flask Show Client IP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, request, jsonify | |
app = Flask(__name__) | |
@app.route('/ip', methods=['GET']) | |
def name(): | |
return request.environ.get('HTTP_X_REAL_IP', request.remote_addr) | |
#return jsonify({'ip': request.remote_addr}), 200 | |
#return jsonify({'ip': request.environ['REMOTE_ADDR']}), 200 | |
if __name__ == '__main__': | |
app.run(host='0.0.0.0', port=80) |
this is return the localhost ip, how to get the public ip with flask?
Perhaps you were running this in development....if you put it on a server (like gunicorn) ... it should return the ip of the client
and how i can change it?
this is return the localhost ip, how to get the public ip with flask?
Perhaps you were running this in development....if you put it on a server (like gunicorn) ... it should return the ip of the client
and how i can change it?
Clearly the IP
is the one sent with the HTTP request
, there are no other IP
s as far as Flask is concerned.
https://werkzeug.palletsprojects.com/en/0.15.x/wrappers/#werkzeug.wrappers.BaseRequest.remote_addr
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Perhaps you were running this in development....if you put it on a server (like gunicorn) ... it should return the ip of the client