Skip to content

Instantly share code, notes, and snippets.

@mcdxn
Last active February 22, 2022 19:27
Show Gist options
  • Save mcdxn/9c3874dbf95a342ea336e1ff4ee25ad8 to your computer and use it in GitHub Desktop.
Save mcdxn/9c3874dbf95a342ea336e1ff4ee25ad8 to your computer and use it in GitHub Desktop.
Find out Local Private IP Address over the Internet
// 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