1

I want to get IP address of requesting client using jQuery. But not by using third party API. On server side i tried following things. Request.ServerVariables["REMOTE_ADDR"];

OR

HttpContext.Current.Request.UserHostAddress to get client request ip address but wants get it on client side using jQuery

Jakob Christensen
  • 14,826
  • 2
  • 51
  • 81

1 Answers1

1

In your server application you would have to create an action such as:

public ActionResult getip()
{
    return Json(Request.UserHostAddress);
}

and call it form jQuery

$.getJSON("http://yourhostname/controller/getip",
    function(ip){
       alert( "Your ip: " + ip);
});

But, this is just a simple example which doesnt deal with clients behind proxies. Check this answer: How can I get the client's IP address in ASP.NET MVC?

Otherwise you have to use thrid party API:

 $.getJSON("http://jsonip.appspot.com?callback=?",
    function(data){
       alert( "Your ip: " + data.ip);
  });
Community
  • 1
  • 1
Artur Kedzior
  • 3,994
  • 1
  • 36
  • 58