获得公网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();

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-06
  • 2022-02-18
  • 2021-07-19
  • 2021-10-21
猜你喜欢
  • 2021-07-15
  • 2021-09-07
  • 2022-12-23
  • 2022-01-14
  • 2022-12-23
相关资源
相似解决方案