Getting IP Address using C#

Hi Viewers,

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());

}



S.VinothkumaR

5 comments:

bala said...

sir i tried it in console.after replacing response.rite into consoe.write it display the result. thanks

Dwaragesh MB said...

How to assign a IP address to a machine???

NANDA KUMAR said...

Awesome...it works fine.Thanks Vinoth..

pat said...

Many Thanks.

arr said...

Thankxxxxx..!