Created
April 26, 2019 23:08
-
-
Save tadeubdev/3965677b551dd90554d490a4c6b03654 to your computer and use it in GitHub Desktop.
Get the actual IP Adress in JavaScript
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
| <script> | |
| 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; | |
| 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]; | |
| alert('My IP is: ' + myIP); | |
| pc.onicecandidate = noop; | |
| }; | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment