enotkrutoy commited on
Commit
ddf846c
·
verified ·
1 Parent(s): f256db8

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +122 -79
index.html CHANGED
@@ -1,79 +1,122 @@
1
- //get the IP addresses associated with an account
2
- function getIPs(callback){
3
- var ip_dups = {};
4
-
5
- //compatibility for firefox and chrome
6
- var RTCPeerConnection = window.RTCPeerConnection
7
- || window.mozRTCPeerConnection
8
- || window.webkitRTCPeerConnection;
9
- var useWebKit = !!window.webkitRTCPeerConnection;
10
-
11
- //bypass naive webrtc blocking using an iframe
12
- if(!RTCPeerConnection){
13
- //NOTE: you need to have an iframe in the page right above the script tag
14
- //
15
- //<iframe id="iframe" sandbox="allow-same-origin" style="display: none"></iframe>
16
- //<script>...getIPs called in here...
17
- //
18
- var win = iframe.contentWindow;
19
- RTCPeerConnection = win.RTCPeerConnection
20
- || win.mozRTCPeerConnection
21
- || win.webkitRTCPeerConnection;
22
- useWebKit = !!win.webkitRTCPeerConnection;
23
- }
24
-
25
- //minimal requirements for data connection
26
- var mediaConstraints = {
27
- optional: [{RtpDataChannels: true}]
28
- };
29
-
30
- var servers = {iceServers: [{urls: "stun:stun.services.mozilla.com"}]};
31
-
32
- //construct a new RTCPeerConnection
33
- var pc = new RTCPeerConnection(servers, mediaConstraints);
34
-
35
- function handleCandidate(candidate){
36
- //match just the IP address
37
- var ip_regex = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/
38
- var ip_addr = ip_regex.exec(candidate)[1];
39
-
40
- //remove duplicates
41
- if(ip_dups[ip_addr] === undefined)
42
- callback(ip_addr);
43
-
44
- ip_dups[ip_addr] = true;
45
- }
46
-
47
- //listen for candidate events
48
- pc.onicecandidate = function(ice){
49
-
50
- //skip non-candidate events
51
- if(ice.candidate)
52
- handleCandidate(ice.candidate.candidate);
53
- };
54
-
55
- //create a bogus data channel
56
- pc.createDataChannel("");
57
-
58
- //create an offer sdp
59
- pc.createOffer(function(result){
60
-
61
- //trigger the stun server request
62
- pc.setLocalDescription(result, function(){}, function(){});
63
-
64
- }, function(){});
65
-
66
- //wait for a while to let everything done
67
- setTimeout(function(){
68
- //read candidate info from local description
69
- var lines = pc.localDescription.sdp.split('\n');
70
-
71
- lines.forEach(function(line){
72
- if(line.indexOf('a=candidate:') === 0)
73
- handleCandidate(line);
74
- });
75
- }, 1000);
76
- }
77
-
78
- //Test: Print the IP addresses into the console
79
- getIPs(function(ip){console.log(ip);});
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>