30

How do you resolve a domain name to an IP address with .NET/C#?

RTB
  • 5,373
  • 7
  • 29
  • 49
Antonio Haley
  • 4,426
  • 1
  • 24
  • 19

2 Answers2

20
using System.Net;

foreach (IPAddress address in Dns.GetHostAddresses("www.google.com"))
{
   Console.WriteLine(address.ToString());
}
Richard J. Ross III
  • 53,315
  • 24
  • 127
  • 192
lubos hasko
  • 23,934
  • 10
  • 52
  • 61
1

Try using the System.Net.Dns class

Kolappan N
  • 2,178
  • 2
  • 26
  • 31
Yaakov Ellis
  • 38,048
  • 29
  • 119
  • 167