from flask import request

def get_ip():
    if not request.headers.get("X-Forwarded-For"):
        return request.remote_addr

    return request.headers.get("X-Forwarded-For")

from flask import request

def get_ip():
    if not request.headers.get("X-Forwarded-For"):
        return request.remote_addr

    return request.headers.get("X-Forwarded-For")[0]

Select the first IP address from the X-Forwarded-For list.
Select the first IP address from the X-Forwarded-For list.
