WPF 获取本地IP地址

  /// 
        /// 获取本地IP地址信息
        /// 
        void GetAddressIP()
        {
            ///获取本地的IP地址
            string AddressIP = string.Empty;
            foreach (IPAddress _IPAddress in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
            {
                if (_IPAddress.AddressFamily.ToString() == "InterNetwork")
                {
                    AddressIP = _IPAddress.ToString();
                }
            }
            txtLocalIP.Text = AddressIP;
        }

 

你可能感兴趣的:(WPF 获取本地IP地址)