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

 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         }

 

posted @ 2023-09-13 16:39  赵三毛  阅读(432)  评论(0)    收藏  举报