namespace AipGateway.API.Service.Utils
{
    public class IPHelper
    {
        public static string GetUserIP(HttpRequest req)
        {
            var ip = req.Headers["X-Forwarded-For"].FirstOrDefault();

            if (!string.IsNullOrWhiteSpace(ip)) ip = ip.Split(',')[0];

            if (string.IsNullOrWhiteSpace(ip)) ip = Convert.ToString(req.HttpContext.Connection.RemoteIpAddress);

            if (string.IsNullOrWhiteSpace(ip)) ip = req.Headers["REMOTE_ADDR"].FirstOrDefault();

            return (ip == null) ? "0.0.0.0" : ip;
        }

    }
}
