ASP.NET: Get Local IP Address Of client system in ASP.NET using C#.

In this article we will learn how to get Local IP Address of the client system in asp.net.



Demo:

In this example I have written the code on Button Click Event:

Asp.NET Code to get Public IP address:

In C#:
 Add Following NameSpaces :

using System.Net;
using System.Net.Sockets;

Now Write Following Code:

  protected string GetIPAddress()
    {
    return Dns.GetHostEntry(Dns.GetHostName()).AddressList.FirstOrDefault(ip => ip.AddressFamily == AddressFamily.InterNetwork).ToString();
    }
protected void btnIpAddress_Click(object sender, EventArgs e)
    {
        string ipAddress = GetIPAddress();
        Response.Write("IP Address: " + ipAddress);
    }




EmoticonEmoticon