Get client IP from javascript or jquery

Question:

How can I get the client's real IP much from Javascript if possible.

This means that there is a direct connection, or through a proxy , or router or whatever, the real IP of the client computer always identifies me.

Implement this code in javascript. But it only works in some cases, and it is that it does not have a proxy, so it does not work for me personally, because it points to the proxy and not to the IP of my machine.

Code:

<!DOCTYPE html>
<html>
  <head>
    <title>IP real</title>
  </head>
  <body>
     Mi IP es: <strong id="ipId"></strong>

    <script type="text/javascript">
        function get_ip(obj){
            document.getElementById('ipId').innerHTML = obj.ip;
        }
    </script>
    <script type="text/javascript" src="https://api.ipify.org/?format=jsonp&callback=get_ip"></script>
  </body>
</html>

Answer:

Using JS , one option would be to use the API of a Web Service, for example Freegeoip , which accepts three response formats JSON XML CSV , the URL is specified as follows.

freegeoip.net/{format}/{IP_or_hostname}
$.getJSON('//freegeoip.net/json/?callback=?', function(data) {
  console.log(data);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

There are more alternatives, some are specified in this Answer

Scroll to Top