asp.net 获取客户机IP地址

/// <summary>
///get  client IP
/// </summary>
/// <returns></returns>
public static string GetIP()
{
    string clientIP = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
    if (String.IsNullOrEmpty(clientIP))
    {
        clientIP = HttpContext.Current.Request.ServerVariables["HTTP_X_REAL_IP"];
    }
    if (string.IsNullOrEmpty(clientIP))
    {
        clientIP = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
    }
    return clientIP;
}
原文地址:https://www.cnblogs.com/weekend001/p/3477423.html