Get IP Address from DNS Hostname in C#
A frequent task when designing applications that work with TCP/IP and the internet is to lookup an IP address from a hostname. It's much easier for users to deal with the hostname than having to type in an IP address. First you'll add the System.Net namespace to your using section:
using System.Net;
Example of code to get address from hostname:
string howtogeek = "www.howtogeek.com";IPAddress[] addresslist = Dns.GetHostAddresses(howtogeek);
foreach (IPAddress theaddress in addresslist)
{
Console.WriteLine(theaddress.ToString());
}
This was tested in C# 2.0.
ncG1vNJzZmivp6x7qbvWraagnZWge6S7zGhoanBfnLK1ecipZJqclKeytL%2BMn6mopV2Zu7R5x6iqraaRorJutc1mmmg%3D