3

This site shows my public IPv6, my public IPv4 and my local ip address. The first and second is clear, but how can a webservice located in the WWW determine my local ip address since a router is made to prevent such practices and is made for isolating the private home network from the global public network.

So my question is, how can a webserice located in internet determine my local ip address my computer uses to talk with others in my local private network?

2 Answers2

4

As it turns out, the recent WebRTC extension of HTML5 allows javascript to query the local client IP address. A proof of concept is available here: http://net.ipcalf.com

This feature is apparently by design, and is not a bug. However, given its controversial nature, I would be cautious about relying on this behaviour. Nevertheless, I think it perfectly and appropriately addresses your intended purpose (revealing to the user what their browser is leaking).

https://webrtc.org/

again
  • 974
  • 8
  • 23
3

Such webservices like whatismyip.com uses javascript to determine your local ip address. Following is the code extracted from the site you mentioned above:

function checkLocal() {
            window.RTCPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;   //compatibility for firefox and chrome
            var pc = new RTCPeerConnection({iceServers: []}), noop = function () {
            };
            pc.createDataChannel("");    //create a bogus data channel
            pc.createOffer(pc.setLocalDescription.bind(pc), noop);    // create offer and set local description
            pc.onicecandidate = function (ice) {  //listen for candidate events
                if (!ice || !ice.candidate || !ice.candidate.candidate) return;
                //reads out local ip
                var myIP = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/.exec(ice.candidate.candidate)[1];
                jQuery(document).ready(function () {
                    jQuery("#local-ip").append("Your Local IP is: " + myIP);
                    jQuery("#local-ip").show("slow");
                });

                pc.onicecandidate = noop;
            };

}

The code binds to your pc (pc is self refering), but with the interface you are capable of reading out the socket details and that includes the local ip under which your computer is known in your local area network. That's a common practice to get your local ip address. It's new to me that can be done with javascript.

For more information about the RTCPeerConnection js API: https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection