Skip to content

Instantly share code, notes, and snippets.

@donno2048
Last active November 6, 2021 18:43
Show Gist options
  • Save donno2048/ac679e16e1da62940929c4846d3ab56d to your computer and use it in GitHub Desktop.
Save donno2048/ac679e16e1da62940929c4846d3ab56d to your computer and use it in GitHub Desktop.
Alert the IP address
// 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