title: How to get the private IP using JavaScript?
body: <p>I am using a code I have found on Github, to get the private network's IP address using WebRTC. </p>
  
  <p>This works perfectly in Chrome, however in Firefox I get only the public IP address in the response. </p>
  
  <p>Is there a fix for this? I'm only targeting most recent versions of these browsers.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>            function getIPs(callback){
                  var ip_dups = {};
  
                  var RTCPeerConnection = window.RTCPeerConnection
                      || window.mozRTCPeerConnection
                      || window.webkitRTCPeerConnection;
  
                  //bypass naive webrtc blocking using an iframe
                  if(!RTCPeerConnection){
                      var win = iframe.contentWindow;
                      RTCPeerConnection = win.RTCPeerConnection
                          || win.mozRTCPeerConnection
                          || win.webkitRTCPeerConnection;
                  }
  
                  //minimal requirements for data connection
                  var mediaConstraints = {
                      optional: [{RtpDataChannels: true}]
                  };
  
                  var servers = {iceServers: [{urls: "stun:stun.l.google.com:19302"}]};
  
                  //construct a new RTCPeerConnection
                  var pc = new RTCPeerConnection(servers, mediaConstraints);
  
                  function handleCandidate(candidate){
                      //match just the IP address
                      var ip_regex = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/
                      var ip_addr = ip_regex.exec(candidate)[1];
  
                      //remove duplicates
                      if(ip_dups[ip_addr] === undefined)
                          callback(ip_addr);
  
                      ip_dups[ip_addr] = true;
                  }
  
                  pc.onicecandidate = function(ice){
                      if(ice.candidate)
                          handleCandidate(ice.candidate.candidate);
                  };
  
                  pc.createDataChannel("");
  
                  pc.createOffer(function(result){
                      pc.setLocalDescription(result, function(){}, function(){});
                  }, function(){});
  
                  //wait for a while to let everything done
                  setTimeout(function(){
                      //read candidate info from local description
                      var lines = pc.localDescription.sdp.split('\n');
  
                      lines.forEach(function(line){
                          if(line.indexOf('a=candidate:') === 0)
                              handleCandidate(line);
                      });
                  }, 1000);
              }
  
              // Get IP
              getIPs(function(ip){
                  if (ip.match(/^(192\.168\.|169\.254\.|10\.|172\.(1[6-9]|2\d|3[01]))/)){
                      console.log('Private ip :' + ip)
                  }else {
                      console.log('Public ip :' + ip)
                  }
              });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;iframe id="iframe" sandbox="allow-same-origin" style="display: none"&gt;&lt;/iframe&gt;
      &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>