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();
        }     
    }
    
}

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.
Pin It

Leave a Reply

Your email address will not be published. Required fields are marked *