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

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...