Free programming examples and instructions

Find Remote IP address in asp.net C#

Demo and code for how to find Reomote IP address in asp.net

by Athil

Posted on 10 Jun 2017 Category: Asp.net Views: 1388

Edited on 06 Aug 2017


Hi, Here I am going to show how to find the Remote address (IP) of the client using asp.net.

string  ip = Request.ServerVariables["REMOTE_ADDR"];


Full Demo Code

On Client Side

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Demo for find ip address in asp.net c#</title>
    <form id="form1" runat="server">
    <h1> Demo for find Ip address Asp.net C# </h1>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Get Ip address" OnClick="Button1_Click" />


On Server Side

  protected void Button1_Click(object sender, EventArgs e)
            TextBox1.Text = GetIPAddress();
        public string GetIPAddress()
            string ip;
            ip = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            if (ip == "" || ip == null)
                ip = Request.ServerVariables["REMOTE_ADDR"];
            return ip;

Leave a Comment: