How to get the IP address of the local machine

Saratvaddilli
Posted by Saratvaddilli under C# category on | Points: 40 | Views : 1192
To get the ip address of the local machine we can use IPHostEntry and Dns in C#

Here is the sample code to get the ip address of the local machine

protected void Page_Load(object sender, EventArgs e)
{

string hostName = Dns.GetHostName();
IPHostEntry local = Dns.GetHostEntry(hostName);
foreach (IPAddress ipaddress in local.AddressList)
{
Response.Write("IPAddress = " + ipaddress.ToString());
}


}

Comments or Responses

Login to post response