Thursday, June 18, 2009

Get IP Address by hostname from Domain name server in C#

This code is in c# to retrieve IP address corresponding to any hostname from Domain name server


string hostname = "www.dotnetspider.com";
IPAddress[] addresslist = Dns.GetHostAddresses(hostname);

foreach (IPAddress theaddress in addresslist)
{
Response.Write(theaddress.ToString());
Response.Write("NewLine");
}


in the second response we have a line brake. age is not visible so i am placing "NewLine" there.

don't forget to use

using System.Net;

No comments: