Cloud Training (Online)

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



Senthil Kumar B
Senthil Kumar is a former Microsoft MVP (Most Valuable Professional). He is a Co-Author of the book "Windows 10 Development Recipes using JavaScript and CSS" for Apress Publication. He is a technical presenter, blogger, mentor and a Geek.  Senthil is a regular speaker is various local user groups. He has presented at conferences like Great Indian Developer Summit (GIDS) & Microsoft DevCamps. You can reach out to him via his Twitter handle @isenthil.