首页 > 开发 > 综合 > 正文

检测客户端显示器分辨率、浏览器类型和客户端IP

2024-07-21 02:17:22
字体:
来源:转载
供稿:网友
下面的代码实现了检测客户端显示器分辨率、浏览器类型和客户端ip的功能。你可以把客户端信息保存到session,viewstate等中以便在其它的页面直接使用。

clientpeek.aspx

<%@ page language="vb" enableviewstate="false" codebehind="clientpeek.aspx.vb"
autoeventwireup="false" inherits="aspxweb.clientpeek"%>
<!doctype html public "-//w3c//dtd html 4.0 transitional//en" >
<html>
<head>
<title>检测客户端显示器分辨率、浏览器类型和客户端ip</title>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<meta content="microsoft visual studio 7.0" name="generator">
<meta content="c#" name="code_language">
<meta content="【孟子e章】:http://xml.sz.luohuedu.net/" name="copyright">
<meta content="javascript" name="vs_defaultclientscript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetschema">
</head>
<body id="mybody" ms_positioning="gridlayout" runat="server">
<form id="browserpeek" runat="server">
<asp:label id="label1" runat="server"></asp:label></form>
</body>
</html>

clientpeek.aspx.vb

imports system

public class clientpeek
inherits system.web.ui.page
protected withevents label1 as system.web.ui.webcontrols.label
protected withevents mybody as system.web.ui.htmlcontrols.htmlgenericcontrol


#region " web 窗体设计器生成的代码 "

'该调用是 web 窗体设计器所必需的。
<system.diagnostics.debuggerstepthrough()> private sub initializecomponent()

end sub

'注意: 以下占位符声明是 web 窗体设计器所必需的。
'不要删除或移动它。
private designerplaceholderdeclaration as system.object

private sub page_init(byval sender as system.object, byval e as system.eventargs) _
handles mybase.init
'codegen: 此方法调用是 web 窗体设计器所必需的
'不要使用代码编辑器修改它。
initializecomponent()
end sub

#end region

private sub page_load(byval sender as system.object, byval e as system.eventargs) _
handles mybase.load
dim button1 as new system.web.ui.webcontrols.button
if not me.ispostback then
dim btnw as new system.web.ui.htmlcontrols.htmlinputhidden
dim btnh as new system.web.ui.htmlcontrols.htmlinputhidden
button1.id = "button1"
btnw.name = "widthpixel"
btnw.id = "widthpixel"
btnh.name = "heightpixel"
btnh.id = "heightpixel"
me.findcontrol("browserpeek").controls.add(btnw)
me.findcontrol("browserpeek").controls.add(btnh)
me.findcontrol("browserpeek").controls.add(button1)
dim scriptstring as string = ""
scriptstring += "document.browserpeek.widthpixel.value=window.screen.width;"
scriptstring += "document.browserpeek.heightpixel.value=window.screen.height;"
me.registeronsubmitstatement("meng", scriptstring)
me.mybody.attributes.add("onload", "document.browserpeek.button1.click();")
else
me.mybody.attributes.remove("onload")
if me.findcontrol("browserpeek").controls.contains(button1) then
me.findcontrol("browserpeek").controls.remove(button1)
button1.dispose()
end if
dim strlabel as new system.text.stringbuilder
dim bc as httpbrowsercapabilities = request.browser
strlabel.append("您的浏览器的分辨率为:")
strlabel.append(request.form("widthpixel"))
strlabel.append("×")
strlabel.append(request.form("heightpixel"))
strlabel.append("<hr color='#000099'>")
strlabel.append("浏览器基本信息:<br>")
strlabel.append("type = " & bc.type & "<br>")
strlabel.append("name = " & bc.browser & "<br>")
strlabel.append("version = " & bc.version & "<br>")
strlabel.append("major version = " & bc.majorversion & "<br>")
strlabel.append("minor version = " & bc.minorversion & "<br>")
strlabel.append("platform = " & bc.platform & "<br>")
strlabel.append("is beta = " & bc.beta & "<br>")
strlabel.append("is crawler = " & bc.crawler & "<br>")
strlabel.append("is aol = " & bc.aol & "<br>")
strlabel.append("is win16 = " & bc.win16 & "<br>")
strlabel.append("is win32 = " & bc.win32 & "<br>")
strlabel.append("支持 frames = " & bc.frames & "<br>")
strlabel.append("支持 tables = " & bc.tables & "<br>")
strlabel.append("支持 cookies = " & bc.cookies & "<br>")
strlabel.append("支持 vb script = " & bc.vbscript & "<br>")
strlabel.append("支持 javascript = " & bc.javascript & "<br>")
strlabel.append("支持 java applets = " & bc.javaapplets & "<br>")
strlabel.append("支持 activex controls = " & bc.activexcontrols & "<br>")
strlabel.append("cdf = " & bc.cdf & "<br>")
strlabel.append("w3cdomversion = " + bc.w3cdomversion.tostring + "<br>")
strlabel.append("useragent = " + request.useragent + "<br>")
strlabel.append("userlanguages = " + request.userlanguages(0).tostring + "<br>")
strlabel.append("<hr color='#000099'>")
strlabel.append("客户端计算机基本配置:<br>")
strlabel.append("userhostname = " + request.userhostname + "<br>")
strlabel.append("userhostaddress = " + request.userhostaddress + "<br>")
label1.text = strlabel.tostring()
end if
end sub

end class

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表