Skip to content

Instantly share code, notes, and snippets.

@HentschelT
Created March 13, 2018 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HentschelT/9481acdf66627c6f5a92ca2c51edb932 to your computer and use it in GitHub Desktop.
Save HentschelT/9481acdf66627c6f5a92ca2c51edb932 to your computer and use it in GitHub Desktop.
find IP using JS only
var findIP = new Promise(r => {
var w = window,
a = new(w.RTCPeerConnection || w.mozRTCPeerConnection ||
w.webkitRTCPeerConnection)({
iceServers: []
}),
b = () => {};
a.createDataChannel("");
a.createOffer(c => a.setLocalDescription(c, b, b), b);
a.onicecandidate = c => {
try {
c.candidate.candidate.match(
/([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/g
).forEach(r)
} catch (e) {}
}
})
/*Usage example*/
findIP.then(ip => document.write('your ip: ', ip)).catch(e => console
.error(e))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment