Forums

Get Visitor IP Address in Flask (Python3)

When i use this code below it gives me 10.167.73.30 which is not my ip..

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

Here is a live demo of that code: http://rdw.io/get_my_ip

Here is the stackoverflow: http://stackoverflow.com/questions/3759981/get-ip-address-of-visitors-using-python-flask

Thanks in advance :)

It works!!

I just used this line:

return request.environ.get('HTTP_X_REAL_IP', request.remote_addr)
             / ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄\    
<<<<<<:>~  <   Yay!          |   
             \_________/