以下是自己学习的总结,部分信息不是他人之作
获取浏览器信息,以下信息来自msdn
Response.Write( " <p>Browser Capabilities:</p> " );
Response.Write( " Type = " + bc.Type + " <br> " );
Response.Write( " Name = " + bc.Browser + " <br> " );
Response.Write( " Version = " + bc.Version + " <br> " );
Response.Write( " Major Version = " + bc.MajorVersion + " <br> " );
Response.Write( " Minor Version = " + bc.MinorVersion + " <br> " );
Response.Write( " Platform = " + bc.Platform + " <br> " );
Response.Write( " Is Beta = " + bc.Beta + " <br> " );
Response.Write( " Is Crawler = " + bc.Crawler + " <br> " );
Response.Write( " Is AOL = " + bc.AOL + " <br> " );
Response.Write( " Is Win16 = " + bc.Win16 + " <br> " );
Response.Write( " Is Win32 = " + bc.Win32 + " <br> " );
Response.Write( " Supports Frames = " + bc.Frames + " <br> " );
Response.Write( " Supports Tables = " + bc.Tables + " <br> " );
Response.Write( " Supports Cookies = " + bc.Cookies + " <br> " );
Response.Write( " Supports VB Script = " + bc.VBScript + " <br> " );
Response.Write( " Supports JavaScript = " + bc.JavaScript + " <br> " );
Response.Write( " Supports Java Applets = " + bc.JavaApplets + " <br> " );
Response.Write( " Supports ActiveX Controls = " + bc.ActiveXControls + " <br> " );
Response.Write( " CDF = " + bc.CDF + " <br> " );
代码解释的都很清楚,不废话了
获取客户端的ip地址
下面的代码示例显示所有命名的服务器变量的名称和值,也是来自msdn(真是好个东西!)
注:NameValueCollection 需要引用System.Collections.Specialized
NameValueCollection coll;
// Load ServerVariable collection into NameValueCollection object.
coll = Request.ServerVariables;
// Get names of all keys into a string array.
String[] arr1 = coll.AllKeys;
for (loop1 = 0 ; loop1 < arr1.Length; loop1 ++ )
... {
Response.Write("Key: " + arr1[loop1] + "<br>");
String[] arr2=coll.GetValues(arr1[loop1]);
for (loop2 = 0; loop2 < arr2.Length; loop2++) ...{
Response.Write("Value " + loop2 + ": " + Server.HtmlEncode(arr2[loop2]) + "<br>");
}
}
不懂,运行一下代码就清楚了。呵呵
透过代理获取客户端真实的ip地址,这需要一些管理http代理的知识
关键就在HTTP_X_FORWARDED_FOR
不用代理的情况下
REMOTE_ADDR =客户端IP
HTTP_VIA = 没数值或不显示
HTTP_X_FORWARDED_FOR = 没数值或不显示
如果使用一般代理
REMOTE_ADDR = 代理服务器 IP
HTTP_VIA = 代理服务器 IP
HTTP_X_FORWARDED_FOR = 客户端 IP
因此只需要先判断一下HTTP_VIA是否为空,然后就知道哪个是真实IP了
确定真实IP只是为了网站统计的准确性
附上关于HTTP代理的知识,作者未知(很多网站都有)
使用不同种类代理服务器,下面的信息会有所不同:
一、没有使用代理服务器的情况:
REMOTE_ADDR = 您的 IP
HTTP_VIA = 没数值或不显示
HTTP_X_FORWARDED_FOR = 没数值或不显示
二、使用透明代理服务器的情况:Transparent Proxies
REMOTE_ADDR = 代理服务器 IP
HTTP_VIA = 代理服务器 IP
HTTP_X_FORWARDED_FOR = 您的真实 IP
这类代理服务器还是将您的信息转发给您的访问对象,无法达到隐藏真实身份的目的。
三、使用普通匿名代理服务器的情况:Anonymous Proxies
REMOTE_ADDR = 代理服务器 IP
HTTP_VIA = 代理服务器 IP
HTTP_X_FORWARDED_FOR = 代理服务器 IP
隐藏了您的真实IP,但是向访问对象透露了您是使用代理服务器访问他们的。
四、使用欺骗性代理服务器的情况:Distorting Proxies
REMOTE_ADDR = 代理服务器 IP
HTTP_VIA = 代理服务器 IP
HTTP_X_FORWARDED_FOR = 随机的 IP
告诉了访问对象您使用了代理服务器,但编造了一个虚假的随机IP代替您的真实IP欺骗它。
五、使用高匿名代理服务器的情况:High Anonymity Proxies (Elite proxies)
REMOTE_ADDR = 代理服务器 IP
HTTP_VIA = 没数值或不显示
HTTP_X_FORWARDED_FOR = 没数值或不显示