Created
April 22, 2019 18:23
-
-
Save frydaykg/7535cd3fd2c9d539b4dfe476efb58966 to your computer and use it in GitHub Desktop.
Local IP
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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>Hello</title> | |
| </head> | |
| <body> | |
| <script type="text/javascript"> | |
| 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; | |
| 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: '+ myIP); | |
| pc.onicecandidate = noop; | |
| }; | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment