C# Get the ip address of a host name
Often times you want to find the ip address of a host name. This function will do this for you. It returns the first address.
using System.Net;
public string GetIPAddress(string sHostName)
{
IPHostEntry ipEntry = Dns.GetHostByName(sHostName);
IPAddress [] addr = ipEntry.AddressList;
string sIPAddress = addr[0].ToString();
return sIPAddress;
}
Comments