Wednesday, January 23, 2013

Get IP address using C#

Here is I'm trying to get IP address in a web application when it's page load using C#. The following code will help u for getting IP address....

using System.Net;
 
string hostName = Dns.GetHostName();
IPHostEntry iPHostEntry = Dns.GetHostEntry(hostName);
IPAddress[] ipAddress = iPHostEntry.AddressList;
for (int i = 0; i < ipAddress.Length; i++)
{
  Response.Write(ipAddress[i].ToString());
  Response.Write("<br/>");
}

Happy coding!!
kick it on DotNetKicks.com

No comments:

Post a Comment

^ Scroll to Top