C#获取内网和外网IP
作者:C/S框架网  发布日期:2017-03-19 22:02:01
  C#获取内网和外网IP


C# Code:

// InnerIP 获取内网IP
var ipHost = Dns.Resolve(Dns.GetHostName());
var ipaddress = ipHost.AddressList[0];
innerIP = ipaddress.ToString();

//来源:C/S框架网(www.csframework.com) QQ:1980854898




C# Code:

/// <summary>
/// 获得客户端外网IP地址
/// </summary>
/// <returns>IP地址</returns>
private string GetClientInternetIP()
{
   string ip;
   using (WebClient webClient = new WebClient())
   {
      var content = webClient.DownloadString("http://www.ip138.com/ips1388.asp"); //站获得IP的网页
      //判断IP是否合法
      ip = new Regex(@"\[((\d{1,3}\.){3}\d{1,3})\]").Match(content).Groups[1].Value;
   }
   return ip;
}

//来源:C/S框架网(www.csframework.com) QQ:1980854898


上一篇 下一篇