Sunday 3 December 2017

C# Program to Display the IP Address of the Machine


Code:

using System;
using System.Net;
namespace Program
{
    class Program
    {
        static void Main()
        {
            String strHostName = string.Empty; //getting the Host Name.
            strHostName = Dns.GetHostName();
            Console.WriteLine("Local Machine's Host Name: " + strHostName);
            IPHostEntry ipEntry = Dns.GetHostEntry(strHostName);// Using Host Name,IP address is obtained.
            IPAddress[] addr = ipEntry.AddressList;

            for (int i = 0; i < addr.Length; i++)
            {
                Console.WriteLine("IP Address {1} : ",addr[i].ToString());
            }
            Console.ReadLine();
        }
    }
}


Output:

Local Machine's Host Name : win7-pc
IP Address : 192.168.1.2


More C# Programs:




















100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...