Saturday, July 19, 2008

GET DNS IPs

To get DNS IPs we need to import System.Net Namespace. It contains Dns.GetHostByName method, IPHostEntry and IPAddress class.

Create two text boxes with txtDomainName and txtIPs ID respectively and create one button with btnGetIps ID.

Put below code in btnGetIps event

try
{
string strIPs = string.Empty;
IPHostEntry ipHE = Dns.GetHostByName(txtDomainName.Text);
IPAddress[] ipAdd = ipHE.AddressList;
foreach (IPAddress ip in ipAdd)
{
strIPs += ip + ",";
}
txtIPs.Text = strIPs;
}
catch (System.Exception ex)
{
Response.Write(ex.Message);
}

Enter domain name in txtDomainName text box and click btnGetIps.
All the IPs of the domain entered in txtDomainName textbox will appear in txtIPs textbox.

Happy Coding :)

No comments:

Site Meter