Cloud Training (Online)




How to translate a Hostname to an IP Address using C# ?

If you need to translate a hostname (for example : Ginktage.com) to its IP Address  , you can use the classes (Dns and IPAddress) to do it.

How to translate a Hostname to an IP Address using C# ?

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;
namespace GinktageConsoleApp
{
    internal class Program
    {
        private static void Main(string[] args)
        {
           string website = "www.Ginktage.com";
           IPAddress[] addresses = Dns.GetHostAddresses(website);
           foreach (var address in addresses)
           {
               Console.Write(address);
           }
           Console.ReadLine();
        }     
    }
    
}

Senthil Kumar B
Senthil Kumar is a former Microsoft MVP (Most Valuable Professional). He is a Co-Author of the book "Windows 10 Development Recipes using JavaScript and CSS" for Apress Publication. He is a technical presenter, blogger, mentor and a Geek.  Senthil is a regular speaker is various local user groups. He has presented at conferences like Great Indian Developer Summit (GIDS) & Microsoft DevCamps. You can reach out to him via his Twitter handle @isenthil.