BurtBlog

一、C#版

 1 //获取内网IP
 2 private string GetInternalIP()
 3 {
 4     IPHostEntry host;
 5     string localIP = "?";
 6     host = Dns.GetHostEntry(Dns.GetHostName());
 7     foreach (IPAddress ip in host.AddressList)
 8     {
 9         if (ip.AddressFamily.ToString() == "InterNetwork")
10         {
11             localIP = ip.ToString();
12             break;
13         }
14     }
15     return localIP;
16 }
 1 //获取外网IP
 2 private string GetExternalIP()
 3 {
 4     string direction = "";
 5     WebRequest request = WebRequest.Create("http://checkip.dyndns.org/");
 6     using (WebResponse response = request.GetResponse())
 7     using (StreamReader stream = new StreamReader(response.GetResponseStream()))
 8     {
 9         direction = stream.ReadToEnd();
10     }
11     int first = direction.IndexOf("Address:") + 9;
12     int last = direction.LastIndexOf("</body>");
13     direction = direction.Substring(first, last - first);
14     return direction;
15 }

 

分类:

技术点:

相关文章:

  • 2021-12-04
  • 2022-12-23
  • 2022-12-23
  • 2021-12-06
  • 2022-01-13
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-17
  • 2021-08-13
  • 2021-10-19
相关资源
相似解决方案