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

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();
        }      
    }
}

 

转载于:https://www.cnblogs.com/tiandsp/p/7440436.html

你可能感兴趣的:(【C#学习笔记】获得本机IP)