asp.net实现获取客户端详细信息
程序员文章站
2023-12-18 12:47:28
本文实例讲述了asp.net实现获取客户端详细信息代码。分享给大家供大家参考。具体如下:
运行效果截图如下:
具体代码如下:
其中aspx页面的控件代码:
复制...
本文实例讲述了asp.net实现获取客户端详细信息代码。分享给大家供大家参考。具体如下:
运行效果截图如下:
具体代码如下:
其中aspx页面的控件代码:
复制代码 代码如下:
<asp:listbox runat="server" id="lbhovertreeinfo" clientidmode="static"> </asp:listbox>
以下是实现代码:
using system; using system.web; using system.web.ui; namespace hovertreetool.hvtinfo.keleyiclient { public partial class index : system.web.ui.page { protected void page_load(object sender, eventargs e) { string useragent = request.useragent == null ? "无" : request.useragent; if (!ispostback) {lbhovertreeinfo.items.add("您的系统信息为:"); lbhovertreeinfo.items.add("客户端ip[page.request.userhostaddress]:"+ page.request.userhostaddress); lbhovertreeinfo.items.add("浏览器类型[request.browser.browser]:" + request.browser.browser); lbhovertreeinfo.items.add("浏览器标识[request.browser.id]:" + request.browser.id); lbhovertreeinfo.items.add("浏览器版本号[request.browser.version]:" + request.browser.version); lbhovertreeinfo.items.add("浏览器是不是测试版本[request.browser.beta]:" + request.browser.beta); lbhovertreeinfo.items.add("浏览器类型[request.browser.type]:" + request.browser.type); lbhovertreeinfo.items.add("是否支持框架网页[request.browser.frames]:" + request.browser.frames); lbhovertreeinfo.items.add("是否支持cookie[request.browser.cookies]:" + request.browser.cookies); lbhovertreeinfo.items.add("浏览器jscript版本[request.browser.jscriptversion]:" + request.browser.jscriptversion); lbhovertreeinfo.items.add("屏幕分辨率宽[system.windows.forms.screen.primaryscreen.bounds.width ]]:" + system.windows.forms.screen.primaryscreen.bounds.width); lbhovertreeinfo.items.add("屏幕分辨率高[system.windows.forms.screen.primaryscreen.bounds.height ]]:" + system.windows.forms.screen.primaryscreen.bounds.height); lbhovertreeinfo.items.add("浏览器类型[request.browser.type]:" + request.browser.type); lbhovertreeinfo.items.add("客户端ip[gethovertreeip()]:" + gethovertreeip()); lbhovertreeinfo.items.add("客户端的操作系统[request.browser.platform]:" + request.browser.platform); lbhovertreeinfo.items.add("客户端的操作系统[gethovertreeosname(useragent)]:" + gethovertreeosname(useragent)); lbhovertreeinfo.items.add("是不是win16系统[request.browser.win16]:" + request.browser.win16); lbhovertreeinfo.items.add("是不是win32系统[request.browser.win32]:" + request.browser.win32); lbhovertreeinfo.items.add("客户端.net framework版本:request.browser.clrversion]:" + request.browser.clrversion); lbhovertreeinfo.items.add("是否支持java[request.browser.javaapplets]:" + request.browser.javaapplets); if (request.servervariables["http_ua_cpu"] == null) lbhovertreeinfo.items.add("cpu 类型[request.servervariables[\"http_ua_cpu\"]]:未知"); else lbhovertreeinfo.items.add("cpu 类型[request.servervariables[\"http_ua_cpu\"]]:" + request.servervariables["http_ua_cpu"]); lbhovertreeinfo.items.add("useragent信息[request.useragent]:" + useragent); lbhovertreeinfo.items.add("by 何问起工具 http://tool.hovertree.com/info/client/"); } } /// <summary> /// 获取真实ip /// </summary> /// <returns></returns> public string gethovertreeip() { string 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; } return result; } /// <summary> /// 根据 user agent 获取操作系统名称 /// </summary> private string gethovertreeosname(string useragent) { string m_hvtosversion = "未知"; if (useragent.contains("nt 6.4")) { m_hvtosversion = "windows 10"; } else if (useragent.contains("nt 6.3")) { m_hvtosversion = "windows 8.1"; } else if (useragent.contains("nt 6.2")) { m_hvtosversion = "windows 8"; } else if (useragent.contains("nt 6.1")) { m_hvtosversion = "windows 7"; }else if (useragent.contains("nt 6.0")) { m_hvtosversion = "windows vista/server 2008"; } else if (useragent.contains("nt 5.2")) { m_hvtosversion = "windows server 2003"; } else if (useragent.contains("nt 5.1")) { m_hvtosversion = "windows xp"; } else if (useragent.contains("nt 5")) { m_hvtosversion = "windows 2000"; } else if (useragent.contains("nt 4")) { m_hvtosversion = "windows nt4"; } else if (useragent.contains("me")) { m_hvtosversion = "windows me"; } else if (useragent.contains("98")) { m_hvtosversion = "windows 98"; } else if (useragent.contains("95")) { m_hvtosversion = "windows 95"; } else if (useragent.contains("mac")) { m_hvtosversion = "mac"; } else if (useragent.contains("unix")) { m_hvtosversion = "unix"; } else if (useragent.contains("linux")) { m_hvtosversion = "linux"; } else if (useragent.contains("sunos")) { m_hvtosversion = "sunos"; } return m_hvtosversion; } } }
以上就是asp.net获取客户端浏览器及主机信息的关键代码,希望对大家的学习有所帮助。