Compare commits
11 commits
62f08b5fac
...
5079f05d5b
Author | SHA1 | Date | |
---|---|---|---|
Cat /dev/Nulo | 5079f05d5b | ||
ba63ef512c | |||
a95b3613e3 | |||
9b890464b8 | |||
bc6099ed96 | |||
108160ef73 | |||
7123a0545d | |||
97685cbdca | |||
d0b47fcfe9 | |||
782cfd27bd | |||
b90175760e |
43
README.md
43
README.md
|
@ -21,21 +21,20 @@ function getIPs(callback){
|
|||
var RTCPeerConnection = window.RTCPeerConnection
|
||||
|| window.mozRTCPeerConnection
|
||||
|| window.webkitRTCPeerConnection;
|
||||
var useWebKit = !!window.webkitRTCPeerConnection;
|
||||
|
||||
//bypass naive webrtc blocking
|
||||
if (!RTCPeerConnection) {
|
||||
var iframe = document.createElement('iframe');
|
||||
//invalidate content script
|
||||
iframe.sandbox = 'allow-same-origin';
|
||||
iframe.style.display = 'none';
|
||||
document.body.appendChild(iframe);
|
||||
//bypass naive webrtc blocking using an iframe
|
||||
if(!RTCPeerConnection){
|
||||
//NOTE: you need to have an iframe in the page right above the script tag
|
||||
//
|
||||
//<iframe id="iframe" sandbox="allow-same-origin" style="display: none"></iframe>
|
||||
//<script>...getIPs called in here...
|
||||
//
|
||||
var win = iframe.contentWindow;
|
||||
window.RTCPeerConnection = win.RTCPeerConnection;
|
||||
window.mozRTCPeerConnection = win.mozRTCPeerConnection;
|
||||
window.webkitRTCPeerConnection = win.webkitRTCPeerConnection;
|
||||
RTCPeerConnection = window.RTCPeerConnection
|
||||
|| window.mozRTCPeerConnection
|
||||
|| window.webkitRTCPeerConnection;
|
||||
RTCPeerConnection = win.RTCPeerConnection
|
||||
|| win.mozRTCPeerConnection
|
||||
|| win.webkitRTCPeerConnection;
|
||||
useWebKit = !!win.webkitRTCPeerConnection;
|
||||
}
|
||||
|
||||
//minimal requirements for data connection
|
||||
|
@ -43,21 +42,14 @@ function getIPs(callback){
|
|||
optional: [{RtpDataChannels: true}]
|
||||
};
|
||||
|
||||
//firefox already has a default stun server in about:config
|
||||
// media.peerconnection.default_iceservers =
|
||||
// [{"url": "stun:stun.services.mozilla.com"}]
|
||||
var servers = undefined;
|
||||
|
||||
//add same stun server for chrome
|
||||
if(window.webkitRTCPeerConnection)
|
||||
servers = {iceServers: [{urls: "stun:stun.services.mozilla.com"}]};
|
||||
var servers = {iceServers: [{urls: "stun:stun.services.mozilla.com"}]};
|
||||
|
||||
//construct a new RTCPeerConnection
|
||||
var pc = new RTCPeerConnection(servers, mediaConstraints);
|
||||
|
||||
function handleCandidate(candidate){
|
||||
//match just the IP address
|
||||
var ip_regex = /([0-9]{1,3}(\.[0-9]{1,3}){3})/
|
||||
var ip_regex = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/
|
||||
var ip_addr = ip_regex.exec(candidate)[1];
|
||||
|
||||
//remove duplicates
|
||||
|
@ -87,14 +79,13 @@ function getIPs(callback){
|
|||
}, function(){});
|
||||
|
||||
//wait for a while to let everything done
|
||||
setTimeout(function() {
|
||||
setTimeout(function(){
|
||||
//read candidate info from local description
|
||||
var lines = pc.localDescription.sdp.split('\n');
|
||||
|
||||
lines.forEach(function(line) {
|
||||
if (line.startsWith('a=candidate:')) {
|
||||
lines.forEach(function(line){
|
||||
if(line.indexOf('a=candidate:') === 0)
|
||||
handleCandidate(line);
|
||||
}
|
||||
});
|
||||
}, 1000);
|
||||
}
|
||||
|
|
56
index.html
56
index.html
|
@ -19,6 +19,9 @@
|
|||
<ul></ul>
|
||||
<h4>Your public IP addresses:</h4>
|
||||
<ul></ul>
|
||||
<h4>Your IPv6 addresses:</h4>
|
||||
<ul></ul>
|
||||
<iframe id="iframe" sandbox="allow-same-origin" style="display: none"></iframe>
|
||||
<script>
|
||||
//get the IP addresses associated with an account
|
||||
function getIPs(callback){
|
||||
|
@ -28,21 +31,20 @@
|
|||
var RTCPeerConnection = window.RTCPeerConnection
|
||||
|| window.mozRTCPeerConnection
|
||||
|| window.webkitRTCPeerConnection;
|
||||
var useWebKit = !!window.webkitRTCPeerConnection;
|
||||
|
||||
//bypass naive webrtc blocking
|
||||
if (!RTCPeerConnection) {
|
||||
var iframe = document.createElement('iframe');
|
||||
//invalidate content script
|
||||
iframe.sandbox = 'allow-same-origin';
|
||||
iframe.style.display = 'none';
|
||||
document.body.appendChild(iframe);
|
||||
//bypass naive webrtc blocking using an iframe
|
||||
if(!RTCPeerConnection){
|
||||
//NOTE: you need to have an iframe in the page right above the script tag
|
||||
//
|
||||
//<iframe id="iframe" sandbox="allow-same-origin" style="display: none"></iframe>
|
||||
//<script>...getIPs called in here...
|
||||
//
|
||||
var win = iframe.contentWindow;
|
||||
window.RTCPeerConnection = win.RTCPeerConnection;
|
||||
window.mozRTCPeerConnection = win.mozRTCPeerConnection;
|
||||
window.webkitRTCPeerConnection = win.webkitRTCPeerConnection;
|
||||
RTCPeerConnection = window.RTCPeerConnection
|
||||
|| window.mozRTCPeerConnection
|
||||
|| window.webkitRTCPeerConnection;
|
||||
RTCPeerConnection = win.RTCPeerConnection
|
||||
|| win.mozRTCPeerConnection
|
||||
|| win.webkitRTCPeerConnection;
|
||||
useWebKit = !!win.webkitRTCPeerConnection;
|
||||
}
|
||||
|
||||
//minimal requirements for data connection
|
||||
|
@ -50,23 +52,18 @@
|
|||
optional: [{RtpDataChannels: true}]
|
||||
};
|
||||
|
||||
//firefox already has a default stun server in about:config
|
||||
// media.peerconnection.default_iceservers =
|
||||
// [{"url": "stun:stun.services.mozilla.com"}]
|
||||
var servers = undefined;
|
||||
|
||||
//add same stun server for chrome
|
||||
if(window.webkitRTCPeerConnection)
|
||||
servers = {iceServers: [{urls: "stun:stun.services.mozilla.com"}]};
|
||||
var servers = {iceServers: [{urls: "stun:stun.services.mozilla.com"}]};
|
||||
|
||||
//construct a new RTCPeerConnection
|
||||
var pc = new RTCPeerConnection(servers, mediaConstraints);
|
||||
|
||||
function handleCandidate(candidate){
|
||||
//match just the IP address
|
||||
var ip_regex = /([0-9]{1,3}(\.[0-9]{1,3}){3})/
|
||||
var ip_addr = ip_regex.exec(candidate)[1];
|
||||
|
||||
if (!candidate) return
|
||||
//https://datatracker.ietf.org/doc/html/rfc5245#section-15.1
|
||||
console.debug(candidate)
|
||||
const things = candidate.split(' ')
|
||||
const ip_addr = things[4]
|
||||
|
||||
//remove duplicates
|
||||
if(ip_dups[ip_addr] === undefined)
|
||||
callback(ip_addr);
|
||||
|
@ -76,7 +73,6 @@
|
|||
|
||||
//listen for candidate events
|
||||
pc.onicecandidate = function(ice){
|
||||
|
||||
//skip non-candidate events
|
||||
if(ice.candidate)
|
||||
handleCandidate(ice.candidate.candidate);
|
||||
|
@ -93,13 +89,13 @@
|
|||
|
||||
}, function(){});
|
||||
|
||||
//wait for a while to let everything done
|
||||
// wait for a while to let everything done
|
||||
setTimeout(function(){
|
||||
//read candidate info from local description
|
||||
var lines = pc.localDescription.sdp.split('\n');
|
||||
|
||||
lines.forEach(function(line){
|
||||
if(line.startsWith('a=candidate:'))
|
||||
if(line.indexOf('a=candidate:') === 0)
|
||||
handleCandidate(line);
|
||||
});
|
||||
}, 1000);
|
||||
|
@ -114,6 +110,10 @@
|
|||
if (ip.match(/^(192\.168\.|169\.254\.|10\.|172\.(1[6-9]|2\d|3[01]))/))
|
||||
document.getElementsByTagName("ul")[0].appendChild(li);
|
||||
|
||||
//IPv6 addresses
|
||||
else if (ip.match(/^[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7}$/))
|
||||
document.getElementsByTagName("ul")[2].appendChild(li);
|
||||
|
||||
//assume the rest are public IPs
|
||||
else
|
||||
document.getElementsByTagName("ul")[1].appendChild(li);
|
||||
|
|
Loading…
Reference in a new issue