Translating or converting a Hostname to an IP Address using C#.

vishalneeraj-24503
Posted by vishalneeraj-24503 under C# category on | Points: 40 | Views : 559
If we need to translate a hostname(for example:dotnetfunda.com ) to its IP Address,then we can use the classes as Dns and IPAddress to do it.

using System.Net;
private static void Main(string[] args)
{
string website = "www.dotnetfunda.com";
IPAddress[] addresses = Dns.GetHostAddresses(website);

foreach (var address in addresses)
{
Console.Write(address);
}
Console.ReadLine();
}

Comments or Responses

Login to post response