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

Aman Sharma
In this article we will learn how to get Local IP Address of the client system in


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

Post a Comment

Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !