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("").FirstOrDefault();