How To Get IP Address Of A System using ASP.NET


First add namespace:

using System.Net;

Code in ASPX page:
<html xmlns=”http://www.w3.org/1999/xhtml”&gt;
<head runat=”server”>
<title>Getting Ip Address</title>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<asp:Label ID=”Label1″ runat=”server”></asp:Label>
</div>
</form>
</body>
</html>
Code Behind:
protected void Page_Load(object sender, EventArgs e)
{
string IP;
IP = Dns.GetHostName();
IPHostEntry ipEntry = Dns.GetHostByName(str);
IPAddress[] addr = ipEntry.AddressList;
for (int i = 0; i < addr.Length; i++)
{
Label1.Text =  “IP Address:” + addr[i].ToString();
}

}