Tools Used : Visual C# .NET
The .Net DNS class can be used to get a host name or an IP of a given host name. To use DNS class in your project, you need to include System.Net
Include System.Net Reference
And say I want to get IP address if www.mindcracker.com. The given code will do that for you.
using System;
using System.Net;
namespace DNSName
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
static void Main(string[] args)
{
IPHostEntry ipEntry = Dns.GetHostByName (http://www.mindcracker.com/);
IPAddress [] IpAddr = ipEntry.AddressList;
for (int i = 0; i < IpAddr.Length; i++)
{
Console.WriteLine ("IP Address {0}: {1} ", i, IpAddr[i].ToString ());
}
}
}
}
Get Local System's host name and IP
Use GetHostName with no parameter to return the host name of a local machine. Once you have host name, pass this host name as a parameter in GetHostByName. See above.
string strHostName = Dns.GetHostName ();
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.

Vithal WadjePosted Nov 23, 2014, 12:13 PM
very useful,thanks for sharing
Manav SainieditedPosted Jul 30, 2011, 5:00 AMEdited Jul 30, 2011, 5:10 AM
sir, when i enter IPHostEntry ipEntry = Dns.GetHostByName (http://www.mindcracker.com/); due to // symbol all the character become comment and error come=ëxpected ) and ;" how to resolve this problem
kishore IrahPosted Mar 26, 2007, 7:58 AM
could you help me out by providing the code for developing an application for collecting information from remote servers using Asp.net and code behind is VB.NET help me on solving this problem? Thanks in advance... kishore