日期:2014-05-18  浏览次数:20814 次

C#获取本地IP
        /// <summary>
        /// 获取本地Ip
        /// </summary>
        private string GetLocalIP()
        {
            IPHostEntry ipHostEntry = Dns.GetHostEntry(Dns.GetHostName());
            if (ipHostEntry.AddressList.Length > 0)
            {
                foreach (IPAddress ipAddress in ipHostEntry.AddressList)
                {
                    if (ipAddress.AddressFamily == AddressFamily.InterNetwork)
                    {
                        return ipAddress.ToString();
                    }
                }
            }
            return string.Empty;
        }

?