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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Clearly the
IP
is the one sent with theHTTP request
, there are no otherIP
s as far as Flask is concerned.https://werkzeug.palletsprojects.com/en/0.15.x/wrappers/#werkzeug.wrappers.BaseRequest.remote_addr