c# 获取本机ip地址的方法

发布时间 2023-09-13 16:43:30作者: 赵三毛
 1 public void GetNativeIp()
 2         {    
 3              IPHostEntry hostEntry = Dns.GetHostEntry(Dns.GetHostName());
 4              foreach(var ip in hostEntry.AddressList)
 5             {
 6                 if (ip.AddressFamily == AddressFamily.InterNetwork)
 7                 {
 8                     IpAddress.Text = ip.ToString();
 9                 }
10             }
11         }