C# - How to display IP ADDRESS

  1. using System;
  2. using System.Net;
  3. namespace Program
  4. {
  5.     class Program
  6.     {
  7.         static void Main()
  8.         {
  9.             String strHostName = string.Empty; //getting the Host Name.
  10.             strHostName = Dns.GetHostName();
  11.             Console.WriteLine("Local Machine's Host Name: " + strHostName);
  12.             IPHostEntry ipEntry = Dns.GetHostEntry(strHostName);// Using Host Name,IP address is obtained.
  13.             IPAddress[] addr = ipEntry.AddressList;
  14.  
  15.             for (int i = 0; i < addr.Length; i++)
  16.             {
  17.                 Console.WriteLine("IP Address {1} : ",addr[i].ToString());
  18.             }
  19.             Console.ReadLine();
  20.         }
  21.     }
  22. }

No comments:

Post a Comment