30

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

RTB
  • 5,773
  • 7
  • 33
  • 50
Antonio Haley
  • 4,702
  • 1
  • 27
  • 19

2 Answers2

20
using System.Net;

foreach (IPAddress address in Dns.GetHostAddresses("www.google.com"))
{
   Console.WriteLine(address.ToString());
}
Richard J. Ross III
  • 55,009
  • 24
  • 135
  • 201
lubos hasko
  • 24,752
  • 10
  • 56
  • 61
1

Try using the System.Net.Dns class

Kols
  • 3,641
  • 2
  • 34
  • 42
Yaakov Ellis
  • 40,752
  • 27
  • 129
  • 174