Last active
          February 22, 2022 19:27 
        
      - 
      
- 
        Save mcdxn/9c3874dbf95a342ea336e1ff4ee25ad8 to your computer and use it in GitHub Desktop. 
    Find out Local Private IP Address over the Internet
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // Code to find out Local IP Address of remote user. | |
| (function (){ | |
| window.RTCPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection; | |
| if (RTCPeerConnection) { | |
| var pc = new RTCPeerConnection({iceServers: []}), noop = function () { | |
| }; | |
| pc.createDataChannel(""); | |
| pc.createOffer(pc.setLocalDescription.bind(pc), noop); | |
| pc.onicecandidate = function (ice) { | |
| if (!ice || !ice.candidate || !ice.candidate.candidate) return; | |
| localIP = /([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]; | |
| console.log(localIP); | |
| pc.onicecandidate = noop; | |
| }; | |
| }})(); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment