获得公网IP

private string GetClientIP()
{
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;
}

 

获得局域网IP:

string ipAddr = Dns.GetHostEntry(Dns.GetHostName()).AddressList[2].ToString();

 

posted on 2016-05-19 19:41  邢帅杰  阅读(171)  评论(0编辑  收藏  举报