;

How to Get the IP Address of the Domain Name in C#


Tutorialsrack 31/07/2020 C#

In this article, we will learn how to get the IP address of the domain name (such as www.tutorialsrack.com, www.google.com, etc) using C#.

Here is the source code of the program to get the IP address of the domain name in C#.

How to Get the IP Address of the Domain Name in C#
using System;
using System.Net;

namespace Tutorialsrack
{
    class Program
    {
        /* How to Get the IP Address of the Domain Name in C# */
        static void Main(string[] args)
        {
            GetDomainIpAddress("www.tutorialsrack.com");
            GetDomainIpAddress("www.google.com");
            GetDomainIpAddress("www.bing.com");
            //Hit ENTER to exit the program
            Console.ReadKey();
        }

        public static void GetDomainIpAddress(string domainName)
        {
            try
            {
                string HostName = domainName;
                IPAddress[] ipaddress = Dns.GetHostAddresses(HostName);
                Console.WriteLine("IPAddress of " + HostName + " is");
                foreach (IPAddress ipaddr in ipaddress)
                {
                    Console.WriteLine(ipaddr);
                }
            }
            catch (Exception) { }
        }
    }
}

I hope this article will help you to understand how to get the IP address of the domain name in c#.

Share your valuable feedback, please post your comment at the bottom of this article. Thank you!


Related Posts



Comments

Recent Posts
Tags