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 @   code_flyer  阅读(197)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示