Created
December 20, 2018 13:03
-
-
Save Steven24K/8fe44c8b319ae203c6bdbbdf9363a54f to your computer and use it in GitHub Desktop.
A Javascript function that returns the users local IP adress
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
function getLocalIP() | |
{ | |
var ip = []; | |
window.RTCPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection || false; | |
if (window.RTCPeerConnection) | |
{ | |
var pc = new RTCPeerConnection({iceServers:[]}), noop = function(){}; | |
pc.createDataChannel(''); | |
pc.createOffer(pc.setLocalDescription.bind(pc), noop); | |
pc.onicecandidate = function(event) | |
{ | |
if (event && event.candidate && event.candidate.candidate) | |
{ | |
var s = event.candidate.candidate.split('\n'); | |
ip.push(s[0].split(' ')[4]); | |
} | |
} | |
} | |
return ip; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment