asp.net 跟js获取 ip地址
时间:2011-05-10 来源:晓宁
c#方法
1 //方法一
2 HttpContext.Current.Request.UserHostAddress;
3
4 //方法二
5 HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
6
7 //方法三
8 string strHostName = System.Net.Dns.GetHostName();
9 string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();
10
11 //方法四(无视代理)
12 HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
js方法
//方法五
var ip = '<!--#echo var="REMOTE_ADDR"-->';
alert("Your IP address is "+ip);
//方法六(无视代理)
function GetLocalIPAddress()
{
var obj = null;
var rslt = "";
try
{
obj = new ActiveXObject("rcbdyctl.Setting");
rslt = obj.GetIPAddress;
obj = null;
}
catch(e)
{
//
}
return rslt;
}
相关阅读 更多 +