Category Archives: C#

Find the IP Addresses of the Local Computer using C#

Using below code we can get all the IP addresses of the local machine in C#,
using system.net namespace.
 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string hostName = Dns.GetHostName();
            IPAddress[] addressArray = Dns.GetHostByName(hostName).AddressList;
            for (int i = 0; i < addressArray.Length; i++)
            {
                Console.WriteLine("{0}", addressArray[i]);
            }
            Console.Read();
        }
    }
}