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 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]);

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s