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

0

1 Answer 1

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);
  });
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.