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

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>