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

Leave A Reply

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

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...