Categories
Asp, Asp.net

How to Get Client Computer IP Address in ASP.Net

How to Get Client Computer IP Address in ASP.Net

In this tutorial we will learn How to Get Client Computer IP Address in ASP.Net.

Design:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>How to Get Client Computer IP Address and Hostname in ASP.Net</title>
<style type="text/css">
body
 {
 width: 980px;
 margin: 0px auto;
 text-align: center;
 padding-top: 50px;
 font-size: 20px;
 }
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>How to Get Client Computer IP Address and Hostname in ASP.Net</h2>  
Your IP Address is:<asp:Label ID="ip" runat="server"></asp:Label>  
<br /><br />
All rights reserved by <a href="http://www.hightechnology.in">www.Hightechnology.in</a> |
     Hosting partner <a href="http://www.grootstech.com" target="_blank">Grootstech</a>  
</div>
</form>
</body>
</html>

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.NetworkInformation;
using System.Net;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ip.Text= Request.UserHostAddress;
    }
}

demo