Categories
Python Answers

How to get IP address of visitors using Flask for Python?

Spread the love

Sometimes, we want to get IP address of visitors using Flask for Python.

In this article, we’ll look at how to get IP address of visitors using Flask for Python.

How to get IP address of visitors using Flask for Python?

To get IP address of visitors using Flask for Python, we can use the request.remote_addr property.

For instance, we write

from flask import request
from flask import jsonify

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

to get the current client’s IP address with request.remote_addr.

Conclusion

To get IP address of visitors using Flask for Python, we can use the request.remote_addr property.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *