Thursday, September 10, 2009

Get the IP address based on the host name

using System.Net;

string HostName = Dns.GetHostName(); //for local machine
public string GetIPAddress(string HostName)
{
IPHostEntry ipHostEntry = Dns.GetHostByName(HostName);
IPAddress [] addres = ipHostEntry.AddressList;
string IPAddress = addres[0].ToString();
return IPAddress;
}

No comments: