Spaces:
Running
Running
Update index.html
Browse files- index.html +122 -79
index.html
CHANGED
@@ -1,79 +1,122 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html>
|
3 |
+
<head>
|
4 |
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
5 |
+
</head>
|
6 |
+
<body>
|
7 |
+
<h4>
|
8 |
+
Demo for:
|
9 |
+
<a href="https://github.com/diafygi/webrtc-ips">
|
10 |
+
https://github.com/diafygi/webrtc-ips
|
11 |
+
</a>
|
12 |
+
</h4>
|
13 |
+
<p>
|
14 |
+
This demo secretly makes requests to STUN servers that can log your
|
15 |
+
request. These requests do not show up in developer consoles and
|
16 |
+
cannot be blocked by browser plugins (AdBlock, Ghostery, etc.).
|
17 |
+
</p>
|
18 |
+
<h4>Your local IP addresses:</h4>
|
19 |
+
<ul></ul>
|
20 |
+
<h4>Your public IP addresses:</h4>
|
21 |
+
<ul></ul>
|
22 |
+
<h4>Your IPv6 addresses:</h4>
|
23 |
+
<ul></ul>
|
24 |
+
<iframe id="iframe" sandbox="allow-same-origin" style="display: none"></iframe>
|
25 |
+
<script>
|
26 |
+
//get the IP addresses associated with an account
|
27 |
+
function getIPs(callback){
|
28 |
+
var ip_dups = {};
|
29 |
+
|
30 |
+
//compatibility for firefox and chrome
|
31 |
+
var RTCPeerConnection = window.RTCPeerConnection
|
32 |
+
|| window.mozRTCPeerConnection
|
33 |
+
|| window.webkitRTCPeerConnection;
|
34 |
+
var useWebKit = !!window.webkitRTCPeerConnection;
|
35 |
+
|
36 |
+
//bypass naive webrtc blocking using an iframe
|
37 |
+
if(!RTCPeerConnection){
|
38 |
+
//NOTE: you need to have an iframe in the page right above the script tag
|
39 |
+
//
|
40 |
+
//<iframe id="iframe" sandbox="allow-same-origin" style="display: none"></iframe>
|
41 |
+
//<script>...getIPs called in here...
|
42 |
+
//
|
43 |
+
var win = iframe.contentWindow;
|
44 |
+
RTCPeerConnection = win.RTCPeerConnection
|
45 |
+
|| win.mozRTCPeerConnection
|
46 |
+
|| win.webkitRTCPeerConnection;
|
47 |
+
useWebKit = !!win.webkitRTCPeerConnection;
|
48 |
+
}
|
49 |
+
|
50 |
+
//minimal requirements for data connection
|
51 |
+
var mediaConstraints = {
|
52 |
+
optional: [{RtpDataChannels: true}]
|
53 |
+
};
|
54 |
+
|
55 |
+
var servers = {iceServers: [{urls: "stun:stun.services.mozilla.com"}]};
|
56 |
+
|
57 |
+
//construct a new RTCPeerConnection
|
58 |
+
var pc = new RTCPeerConnection(servers, mediaConstraints);
|
59 |
+
|
60 |
+
function handleCandidate(candidate){
|
61 |
+
//match just the IP address
|
62 |
+
var ip_regex = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/
|
63 |
+
var ip_addr = ip_regex.exec(candidate)[1];
|
64 |
+
|
65 |
+
//remove duplicates
|
66 |
+
if(ip_dups[ip_addr] === undefined)
|
67 |
+
callback(ip_addr);
|
68 |
+
|
69 |
+
ip_dups[ip_addr] = true;
|
70 |
+
}
|
71 |
+
|
72 |
+
//listen for candidate events
|
73 |
+
pc.onicecandidate = function(ice){
|
74 |
+
|
75 |
+
//skip non-candidate events
|
76 |
+
if(ice.candidate)
|
77 |
+
handleCandidate(ice.candidate.candidate);
|
78 |
+
};
|
79 |
+
|
80 |
+
//create a bogus data channel
|
81 |
+
pc.createDataChannel("");
|
82 |
+
|
83 |
+
//create an offer sdp
|
84 |
+
pc.createOffer(function(result){
|
85 |
+
|
86 |
+
//trigger the stun server request
|
87 |
+
pc.setLocalDescription(result, function(){}, function(){});
|
88 |
+
|
89 |
+
}, function(){});
|
90 |
+
|
91 |
+
//wait for a while to let everything done
|
92 |
+
setTimeout(function(){
|
93 |
+
//read candidate info from local description
|
94 |
+
var lines = pc.localDescription.sdp.split('\n');
|
95 |
+
|
96 |
+
lines.forEach(function(line){
|
97 |
+
if(line.indexOf('a=candidate:') === 0)
|
98 |
+
handleCandidate(line);
|
99 |
+
});
|
100 |
+
}, 1000);
|
101 |
+
}
|
102 |
+
|
103 |
+
//insert IP addresses into the page
|
104 |
+
getIPs(function(ip){
|
105 |
+
var li = document.createElement("li");
|
106 |
+
li.textContent = ip;
|
107 |
+
|
108 |
+
//local IPs
|
109 |
+
if (ip.match(/^(192\.168\.|169\.254\.|10\.|172\.(1[6-9]|2\d|3[01]))/))
|
110 |
+
document.getElementsByTagName("ul")[0].appendChild(li);
|
111 |
+
|
112 |
+
//IPv6 addresses
|
113 |
+
else if (ip.match(/^[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7}$/))
|
114 |
+
document.getElementsByTagName("ul")[2].appendChild(li);
|
115 |
+
|
116 |
+
//assume the rest are public IPs
|
117 |
+
else
|
118 |
+
document.getElementsByTagName("ul")[1].appendChild(li);
|
119 |
+
});
|
120 |
+
</script>
|
121 |
+
</body>
|
122 |
+
</html>
|