using System; using System.Net; namespace ConsoleApplication { class Program { static void Main(string[] args) { IPHostEntry ipHost = Dns.GetHostEntry(Dns.GetHostName()); //v6地址 // IPHostEntry ipHost = Dns.GetHostByName(Dns.GetHostName()); //v4地址 IPAddress ipAddr = ipHost.AddressList[0]; Console.Write(ipAddr.ToString()); Console.Read(); } } }