• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

ASP.NET获取客户端IP地址、系统版本、浏览器版本

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

转自:  http://blog.sina.com.cn/s/blog_40d62aad0100hjic.html

//获取浏览器版本号
    public string getBrowser() {
        string browsers;
        HttpBrowserCapabilities bc = HttpContext.Current.Request.Browser;
        string aa = bc.Browser.ToString();
        string bb = bc.Version.ToString();
        browsers = aa + bb;
        return browsers;
    }
    //获取客户端IP地址
    public string getIP()
    {
        string result = String.Empty;
        result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
        if (null == result || result == String.Empty)
        {
            result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
        }
        if (null == result || result == String.Empty)
        {
            result = HttpContext.Current.Request.UserHostAddress;
        }
        if (null == result || result == String.Empty)
        {
            return "0.0.0.0";
        }
        return result;
    }
    //获取操作系统版本号
    public static string SystemCheck()
    {
        string Agent = HttpContext.Current.Request.ServerVariables["HTTP_USER_AGENT"];

        if (Agent.IndexOf("NT 4.0") > 0)
        {
            return "Windows NT ";
        }
        else if (Agent.IndexOf("NT 5.0") > 0)
        {
            return "Windows 2000";
        }
        else if (Agent.IndexOf("NT 5.1") > 0)
        {
            return "Windows XP";
        }
        else if (Agent.IndexOf("NT 5.2") > 0)
        {
            return "Windows 2003";
        }
        else if (Agent.IndexOf("NT 6.0") > 0)
        {
            return "Windows Vista";
        }
        else if (Agent.IndexOf("WindowsCE") > 0)
        {
            return "Windows CE";
        }
        else if (Agent.IndexOf("NT") > 0)
        {
            return "Windows NT ";
        }
        else if (Agent.IndexOf("9x") > 0)
        {
            return "Windows ME";
        }
        else if (Agent.IndexOf("98") > 0)
        {
            return "Windows 98";
        }
        else if (Agent.IndexOf("95") > 0)
        {
            return "Windows 95";
        }
        else if (Agent.IndexOf("Win32") > 0)
        {
            return "Win32";
        }
        else if (Agent.IndexOf("Linux") > 0)
        {
            return "Linux";
        }
        else if (Agent.IndexOf("SunOS") > 0)
        {
            return "SunOS";
        }
        else if (Agent.IndexOf("Mac") > 0)
        {
            return "Mac";
        }
        else if (Agent.IndexOf("Linux") > 0)
        {
            return "Linux";
        }
        else if (Agent.IndexOf("Windows") > 0)
        {
            return "Windows";
        }
        return "未知类型";

    }


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Asp.netPageDataSource分页发布时间:2022-07-10
下一篇:
ASP.NETMVC5网站开发实践(二)Member区域-添加文章发布时间:2022-07-10
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap