-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
370 lines (354 loc) · 10.1 KB
/
script.js
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
function init_map_ipv4(lat, lng) {
var uluru = {lat: lat, lng: lng};
var map_ipv4 = new google.maps.Map(document.getElementById('map-ipv4'), {
zoom: 10,
center: uluru
});
var marker = new google.maps.Marker({
position: uluru,
map: map_ipv4
});
}
function init_map_ipv6(lat, lng) {
var uluru = {lat: lat, lng: lng};
var map_ipv6 = new google.maps.Map(document.getElementById('map-ipv6'), {
zoom: 10,
center: uluru
});
var marker = new google.maps.Marker({
position: uluru,
map: map_ipv6
});
}
function translate_link_type(link_type){
var lang = navigator.language || navigator.userLanguage;
lang = lang.substr(0,2);
if(lang == 'de'){
var link_types = {
'Ethernet or modem': 'Netzwerk oder Modem',
'L2TP': 'L2TP oder PPPoE',
'Probably IPsec or other VPN': 'IPsec oder anderes VPN',
'generic tunnel or VPN': 'Generischer Tunnel, VPN oder LTE',
'IPSec or GRE': 'IPSec oder Generic Routing Encapsulation',
'IPIP or SIT': 'IPIP oder SIT',
'': '-'
}
} else {
var link_types = {
'Ethernet or modem': 'Ethernet or Modem',
'L2TP': 'L2TP or PPPoE',
'Probably IPsec or other VPN': 'IPsec or other VPN',
'generic tunnel or VPN': 'Generic Tunnel, VPN or LTE',
'IPSec or GRE': 'IPSec or Generic Routing Encapsulation',
'': '-'
}
}
if(lang == 'de'){
var probably = ' (vermutlich)';
} else {
var probably = ' (probably)';
}
if (link_type == '???'){
return '-';
} else if (link_types[link_type] == undefined){
return link_type + probably;
} else{
return link_types[link_type] + probably;
}
}
function format_dns(ip, data){
return ip + '<br/>' + data.isp + '<br/>' + data.country + ' <img src="flags/' + data.country_code.toLowerCase() + '.svg" width="20" height="16" style="margin-bottom: 2px;">';
}
function format_isp(data){
isp = '';
if(present(data.isp_website)){
isp = '<a href="' + data.isp_website + '" target="_blank">' + data.isp + '</a>';
}
else{
isp = data.isp;
}
if(present(data.zip)){
if(isp.substr(-5) != '<br/>'){
isp += '<br/>';
}
isp += data.zip;
}
if(present(data.city)){
if(present(data.zip)){
isp += ' ';
}
else if(isp.substr(-5) != '<br/>'){
isp += '<br/>';
}
isp += data.city;
}
if(present(data.country)){
if(isp.substr(-5) != '<br/>'){
isp += '<br/>';
}
isp += data.country + ' <img src="flags/' + data.country_code.toLowerCase() + '.svg" width="20" height="16" style="margin-bottom: 2px;">';
}
return isp;
}
function format_as(data){
as = '';
if(present(data.as_number)){
as += '#' + data.as_number;
}
if(present(data.as_name)){
if(present(data.as_number)){
as += ', ';
}
as += data.as_name;
}
if(present(data.as_number)){
if(as.substr(-5) != '<br/>'){
as += '<br/>';
}
as += data.as_organisation;
}
if(present(data.as_street)){
if(as.substr(-5) != '<br/>'){
as += '<br/>';
}
as += data.as_street;
}
if(present(data.as_zip)){
if(as.substr(-5) != '<br/>'){
as += '<br/>';
}
as += data.as_zip;
}
if(present(data.as_city)){
if(present(data.as_zip)){
as += ' ';
}
as += data.as_city;
}
if(present(data.as_country)){
if(as.substr(-5) != '<br/>'){
as += '<br/>';
}
as += data.as_country + ' <img src="flags/' + data.as_country_code.toLowerCase() + '.svg" width="20" height="16" style="margin-bottom: 2px;">';
}
return as;
}
function present(val){
return !(val === undefined || val == null || val.length <= 0)
}
$(document).ready(function(){
$.ajax({
url: location.protocol + '//ipv4.' + location.host + '/ip.php',
type: 'GET',
crossDomain: true,
success: function(data){
$('#content-ipv4-ip').text(data);
get_ipv4_host();
get_ipv4_network();
get_ipv4_data();
},
error: function(error){
$('#content-ipv4-ip').text('-');
$('#content-ipv4-hostname').text('-');
$('#content-ipv4-mtu').text('-');
$('#content-ipv4-link-type').text('-');
$('#content-ipv4-distance').text('-');
$('#content-ipv4-ip-network').text('-');
$('#content-ipv4-isp').text('-');
$('#content-ipv4-as').text('-');
}
});
$.ajax({
url: location.protocol + '//ipv6.' + location.host + '/ip.php',
type: 'GET',
crossDomain: true,
success: function(data){
$('#content-ipv6-ip').html(data.replace(/:/g, ':<wbr>'));
get_ipv6_host();
get_ipv6_network();
get_ipv6_data();
},
error: function(error){
$('#content-ipv6-ip').text('-');
$('#content-ipv6-hostname').text('-');
$('#content-ipv6-mtu').text('-');
$('#content-ipv6-link-type').text('-');
$('#content-ipv6-distance').text('-');
$('#content-ipv6-ip-network').text('-');
$('#content-ipv6-isp').text('-');
$('#content-ipv6-as').text('-');
}
});
get_dns_data();
function get_ipv4_host() {
$.ajax({
url: location.protocol + '//ipv4.' + location.host + '/host.php',
type: 'GET',
crossDomain: true,
success: function(data){
if (data == $('#content-ipv4-ip').text()) {
$('#content-ipv4-hostname').text('-');
}
else{
$('#content-ipv4-hostname').text(data);
}
},
error: function(error){
$('#content-ipv4-hostname').text('-');
}
});
}
function get_ipv6_host() {
$.ajax({
url: location.protocol + '//ipv6.' + location.host + '/host.php',
type: 'GET',
crossDomain: true,
success: function(data){
if (data == $('#content-ipv6-ip').text()) {
$('#content-ipv6-hostname').text('-');
}
else{
$('#content-ipv6-hostname').text(data);
}
},
error: function(error){
$('#content-ipv6-hostname').text('-');
}
});
};
function get_ipv4_data() {
$.ajax({
url: location.protocol + '//ipv4.' + location.host + '/geo.php',
type: 'GET',
crossDomain: true,
success: function(data){
if (data && data.status && data.status == 'success') {
$('#content-ipv4-ip-network').text(data.ip_network);
$('#content-ipv4-isp').html(format_isp(data));
$('#content-ipv4-as').html(format_as(data));
$('#map-ipv4').addClass('map-height');
init_map_ipv4(data.lat, data.lon);
}
else {
$('#content-ipv4-ip-network').text('-');
$('#content-ipv4-isp').text('-');
$('#content-ipv4-as').text('-');
}
}
});
};
function get_ipv6_data(ip) {
$.ajax({
url: location.protocol + '//ipv6.' + location.host + '/geo.php',
type: 'GET',
crossDomain: true,
success: function(data){
if (data && data.status && data.status == 'success') {
$('#content-ipv6-ip-network').text(data.ip_network);
$('#content-ipv6-isp').html(format_isp(data));
$('#content-ipv6-as').html(format_as(data));
$('#map-ipv6').addClass('map-height');
init_map_ipv6(data.lat, data.lon);
}
else {
$('#content-ipv6-ip-network').text('-');
$('#content-ipv6-isp').text('-');
$('#content-ipv6-as').text('-');
}
}
});
};
function get_dns_data() {
var lang = navigator.language || navigator.userLanguage;
lang = lang.substr(0,2);
if(lang != 'de'){
lang == 'en';
}
var random_string = '';
for (i = 0; i < 32; i++) {
random_string += '0123456789abcdefghijklmnopqrstuvwxyz'[Math.round(Math.random() * 35)]
}
$.ajax({
url: location.protocol + '//' + random_string + '.edns.ip-api.com/json?lang=' + lang,
type: 'GET',
crossDomain: true,
success: function(data){
$.ajax({
url: location.protocol + '//' + location.host + '/geo.php',
type: 'GET',
crossDomain: true,
headers: {
'X-Client-IP': data.dns.ip
},
success: function(data2){
if (data2 && data2.status && data2.status == 'success') {
$('#content-dns').html(format_dns(data.dns.ip, data2));
}
else {
$('#content-dns').text('-');
}
}
});
if(data && data.edns){
$.ajax({
url: location.protocol + '//' + location.host + '/geo.php',
type: 'GET',
crossDomain: true,
headers: {
'X-Client-IP': data.edns.ip
},
success: function(data3){
if (data3 && data3.status && data3.status == 'success') {
$('#content-edns').html(format_dns(data.edns.ip, data3));
}
else {
$('#content-edns').text('-');
}
}
});
}
else {
$('#content-edns').text('-');
}
},
error: function(error){
$('#content-dns').text('-');
$('#content-edns').text('-');
}
});
};
function get_ipv4_network(){
$.ajax({
url: location.protocol + '//ipv4.' + location.host + '/network.php',
type: 'GET',
crossDomain: true,
success: function(data){
$('#content-ipv4-mtu').text(data.mtu);
$('#content-ipv4-link-type').text(translate_link_type(data.link_type));
$('#content-ipv4-distance').text(data.distance);
},
error: function(error){
$('#content-ipv4-mtu').text('-');
$('#content-ipv4-link-type').text('-');
$('#content-ipv4-distance').text('-');
}
});
};
function get_ipv6_network(){
$.ajax({
url: location.protocol + '//ipv6.' + location.host + '/network.php',
type: 'GET',
crossDomain: true,
success: function(data){
$('#content-ipv6-mtu').text(data.mtu);
$('#content-ipv6-link-type').text(translate_link_type(data.link_type));
$('#content-ipv6-distance').text(data.distance);
},
error: function(error){
$('#content-ipv6-mtu').text('-');
$('#content-ipv6-link-type').text('-');
$('#content-ipv6-distance').text('-');
}
});
};
});