Updated on Kisan Patel
If you have a hostname such as google.com, and you need to obtain the IP address then use the Dns.GetHostEntry
method.
Namespace:
using System.Net;
Program
class Program { static void Main(string[] args) { IPHostEntry iphost = System.Net.Dns.GetHostEntry("www.google.com"); IPAddress[] addresses = iphost.AddressList; foreach (IPAddress address in addresses) { Console.WriteLine("IP Address: {0};", address.ToString()); } Console.ReadKey(); } }
Output of the above program…