服务端:
//方法一
HttpContext.Current.Request.UserHostAddress;
//方法二
HttpContext.Current.Request.ServerVariables[“REMOTE_ADDR”];
//方法三
string strHostName = System.Net.Dns.GetHostName();
string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue
(0).ToString();
//方法四(无视代理,使用cdn加速可以用这个)
HttpContext.Current.Request.ServerVariables[“HTTP_X_FORWARDED_FOR”];
客户端:
//方法五
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;
}
原文链接:https://www.cnblogs.com/ytmf007/p/4645599.html
原创文章,作者:优速盾-小U,如若转载,请注明出处:https://www.cdnb.net/bbs/archives/20805