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;
}
posted @ 2013-12-16 21:13  code_flyer  阅读(196)  评论(0编辑  收藏  举报