【C#学习笔记】获得本机IP

时间:2021-09-13 06:17:53
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[];

            Console.Write(ipAddr.ToString());
            Console.Read();
        }
    }
}