HomeCSharpHow to Get the IP address of a domain name in C# ?

How to Get the IP address of a domain name in C# ?

There are times when you want to resolve the domain name to an IP address programmatically from your C# Application . In this case , you can use the Dns.GetHostAddresses method defined in the System.Net namespace.

The Dns.GetHostAddresses returns an array of type System.Net.IPAddress which contains the IP addresses for the host that is specified by the hostname parameter.

How to Get the IP address of a domain name in C# ?

Below is a code snippet demonstrating the usage of Dns.GetHostAddresses to get the IP address of the domain name.

using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace MobileOSGeekApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var Address = Dns.GetHostAddresses("www.developerpublish.com").FirstOrDefault();
            Console.WriteLine(Address.ToString());          
            Console.ReadLine();
        }
       
    }
    
}

 

image

Leave a Reply

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...