Last active
November 6, 2021 18:43
-
-
Save donno2048/ac679e16e1da62940929c4846d3ab56d to your computer and use it in GitHub Desktop.
Alert the IP address
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
// alert the IP address | |
var myPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection; var pc = new myPeerConnection({iceServers: [{urls: 'stun:stun.l.google.com:19302'}]}), ipRegex = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/g; pc.createDataChannel(''); pc.createOffer(function(sdp) {pc.setLocalDescription(sdp, () => {}, () => {});}, () => {}); pc.onicecandidate = function(ice) {if (ice && ice.candidate && ice.candidate.candidate && ice.candidate.candidate.match(ipRegex)) alert('Your IP address is: ' + ice.candidate.candidate.match(ipRegex)[0]);}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment