WPF 获取本地IP地址

  /// <summary>
        /// 获取本地IP地址信息
        /// </summary>
        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;
        }

 

posted @ 2013-05-10 08:54  幕三少  阅读(4080)  评论(1编辑  收藏  举报