C#获取本地IP地址

2012-06-05
   /// <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 @ 2012-06-05 09:29  在 水 一 方  阅读(45959)  评论(7编辑  收藏  举报