How to get IP address of visitors (Flask and Python)


from flask import request, jsonify

Flask endpoint and code:

@app.route("/get_my_ip", methods=["GET"])
def get_my_ip():
    return jsonify({'ip': request.remote_addr}), 200

request.remote_addr contains the strong of the IPv4 Address

Another way:

from flask import request
request.environ.get('HTTP_X_REAL_IP', request.remote_addr)

Stack overflow post:

0 comments on “How to get IP address of visitors (Flask and Python)Add yours →

Leave a Reply

Your email address will not be published.