-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ip.html
861 lines (773 loc) · 24.6 KB
/
ip.html
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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
<!DOCTYPE html>
<meta charset="UTF-8">
<link rel="canonical" href="https://ip.wtf">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
{{- if eq (.RawRequest.Header.Get "From") "" -}}
{{- if eq .RawRequest.URL.Path "/fun/reverse" }}
{{- if .RIPv4 -}}
ftw.pi: {{ .RIPv4 }}
{{- else }}
ftw.pi: {{ .RIPv6 }}
{{- end -}}
{{- else -}}
{{- if .IPv4 -}}
{{- .Host }}: {{ .IPv4 }}
{{- else }}
{{- .Host }}: {{ .IPv6 }}
{{- end -}}
{{- end -}}
{{- else -}}
WTF is my IP address⁉️
{{- end -}}
</title>
<meta name="description" content="Tells you what your IP addresses (IPv4 and IPv6) are, plus HTTP connection, DNS and browser details.">
<style>
body {
margin: 0;
}
header {
padding-bottom: 12px;
}
.topemoji {
position: absolute;
top: 10px;
right: 4px;
font-size: 150%;
}
.topemoji a {
text-decoration: none;
}
h1 {
text-align: center;
font-style: italic;
padding: 8px;
border-bottom: 2px solid black;
margin-top: 0;
margin-bottom: 1.2rem;
background: #69f;
{{ if eq .RawRequest.URL.Path "/fun/reverse" }}
unicode-bidi: bidi-override;
direction: rtl;
{{ end }}
}
h1 a, .ip a {
color: black;
}
article {
margin: 0 auto;
width: 93%;
}
pre code {
display: block;
color: #333;
background-color: #f9f9f9;
padding: 4px 6px;
border: 1px solid #eee;
border-left-width: 20px;
line-height: 1.1;
overflow: auto;
}
@media only screen and (min-width: 768px) {
article {
width: 60%;
}
}
.ip {
text-align: center;
font-size: 150%;
{{ if eq .RawRequest.URL.Path "/fun/reverse" }}
unicode-bidi: bidi-override;
direction: rtl;
{{ end }}
}
.ipv4, .ipv6 {
font-weight: bold;
{{ if eq .RawRequest.URL.Path "/fun/reverse" }}
unicode-bidi: bidi-override;
direction: rtl;
{{ end }}
}
.ipv4 {
font-size: 280%;
color: red;
}
.ipv6 {
font-size: 150%;
color: green;
}
#extra-ip, #only-ip, #ip-space, .details {
margin-top: 2em;
{{ if eq .RawRequest.URL.Path "/fun/reverse" }}
unicode-bidi: bidi-override;
direction: rtl;
{{ end }}
}
.hidden, #extra-ip, #only-ip {
display: none;
}
.details a[href^="https://bgp.tools"] {
font-size: 90%;
}
.details .country {
font-size: 145%;
vertical-align: middle;
}
.details .city {
vertical-align: middle;
}
#ipv4-details .country, #ipv6-details .country {
font-size: 200%;
line-height: 1.2em;
}
.host {
line-height: 1.2em;
}
pre#http-request {
width: 100%;
overflow-y: scroll;
padding: 5px;
border: 1px solid #ccc;
border-radius: 2px;
background: #f0f0f0;
}
pre#http-request a {
color: black;
text-decoration: none;
}
pre#http-request a:hover {
text-decoration: underline;
}
table.details-table {
border: 0;
width: 100%;
}
.details-table td {
vertical-align: top;
width: 50%;
}
details {
margin-bottom: .5em;
}
details a {
padding-left: 1em;
}
summary:focus {
outline: none;
}
details ul {
list-style: none;
}
details ul li {
margin-left: 1em;
text-indent: -1em;
}
footer {
margin-top: 1.5em;
text-align: center;
font-size: 90%;
}
footer, footer a {
color: #ccc;
}
footer ul li {
display: inline;
list-style-type: none;
}
footer li:not(:first-child)::before {
content: " • ";
}
@media (prefers-color-scheme: dark) {
body {
background: #111;
color: #ddd;
}
h1 {
background: #049;
border-bottom: 2px solid #bbb;
}
h1 a, .ip a {
color: #ddd;
}
pre#http-request {
background: #444;
}
pre {
color: #ddd;
}
pre#http-request a {
color: #ddd;
}
a {
color: #ccf;
}
pre code {
color: #ddd;
background-color: #333;
border: 1px solid #555;
}
}
{{ if eq (.RawRequest.Header.Get "Sec-CH-UA-Platform") "\"Windows\"" }}
@font-face {
font-family: "Twemoji Country Flags";
unicode-range: U+1F1E6-1F1FF, U+1F3F4, U+E0062-E0063, U+E0065, U+E0067,
U+E006C, U+E006E, U+E0073-E0074, U+E0077, U+E007F;
src: url('/.static/TwemojiCountryFlags.woff2') format('woff2');
font-display: swap;
}
* {
font-family: "Twemoji Country Flags", serif;
}
{{ end }}
</style>
<script>
const dnsErrors = ["NOERROR", "FORMERR", "SERVFAIL", "NXDOMAIN", "NOTIMP",
"REFUSED", "YXDOMAIN", "XRRSET", "NOTAUTH", "NOTZONE"];
async function resolve(name, type="PTR") {
return fetch("https://{{ if .IPv4 }}8.8.8.8{{ else }}[2001:4860:4860::8888]{{ end }}/resolve?name=" + encodeURIComponent(name) + "&type=" + type)
.then(r => r.json());
}
async function fetchIPDetails(ip) {
return fetch("/" + encodeURIComponent(ip), {
headers: {
Accept: "application/json"
}
}).then(r => r.json());
}
async function fetchDNS(name) {
return fetch("//" + name + "-{{ .DNSID }}{{ .DNSHost }}")
.then(r => r.json());
}
async function ipv4details(ip) {
const sel = '#ipv4-details';
doIPDetails(sel, ip, ipDetails);
let parts = ip.split('.');
let name = parts.reverse().join('.') + ".in-addr.arpa";
let result = await resolve(name);
displayIPDetails(sel, ip, result);
if (!ipDetails[ip]) {
ipDetails[ip] = await fetchIPDetails(ip);
}
doIPDetails(sel, ip, ipDetails);
}
async function ipv6details(ip) {
const sel = '#ipv6-details';
doIPDetails(sel, ip, ipDetails);
let result = await resolve(ipv6reverse(ip));
displayIPDetails(sel, ip, result);
if (!ipDetails[ip]) {
ipDetails[ip] = await fetchIPDetails(ip);
}
doIPDetails(sel, ip, ipDetails);
}
function makeFlag(isoCode) {
const emojiBase = 0x1F1E6; // Regional Indicator Symbol Letter A
const base = 0x41; // "A"
let res = "";
for (let i = 0; i < isoCode.length; i++) {
res += String.fromCodePoint(emojiBase + isoCode.charCodeAt(i) - base);
}
return res;
}
function doIPDetails(selector, cls, ipDetails) {
let details = document.querySelector(selector);
let flag = details.querySelector(".country");
let city = details.querySelector(".city");
let asnText = details.querySelector(".asn");
if (ipDetails[cls]) {
if (ipDetails[cls].location.country) {
let location = ipDetails[cls].location;
let country = location.country;
flag.textContent = makeFlag(country);
flag.title = location.country_name;
if (city) {
city.textContent = location.city;
}
} else {
const unknown = ["🛸", "👽"];
flag.textContent = unknown[Math.floor(unknown.length*Math.random())];
flag.title = "Unknown country!";
}
if (asnText) {
let num = ipDetails[cls].as.number;
if (num) {
asnText.textContent = num + " (" + ipDetails[cls].as.name + ")";
} else {
const unknown = ["⍰", "﹖"];
asnText.textContent = unknown[Math.floor(unknown.length*Math.random())];
asnText.title = "Unknown AS number!";
}
}
} // otherwise waiting for the result
}
function displayIPDetails(selector, ip, result) {
let details = document.querySelector(selector);
details.classList.remove('hidden');
details.querySelector("a").href = "https://bgp.tools/search?q=" + ip;
let host = details.querySelector(".host");
if (result.Status != 0) { // !OK
host.textContent = "none, got " + dnsErrors[result.Status];
return;
}
host.textContent = result.Answer[0].data;
host.style.fontWeight = 'bold';
}
function ipv6reverse(ip) {
// Need to decompose IP into single hex digits, for ip6.arpa lookup
let parts = ip.split('::');
// Resolve "::" first
let expanded = parts[0].split(':');
if (parts.length > 1) {
let left = parts[0].split(':');
let right = parts[1].split(':');
// Need 8 of 4 nibble parts (i.e. delimited by ':')
let needed = 8 - (right.length - left.length);
let add = new Array(needed);
add.fill('0');
expanded = [left, add, right].flat();
}
return expanded.map(part => ("0".repeat(4 - part.length) + part).split('')).flat().reverse().join('.')
+ ".ip6.arpa";
}
function dump(selector, name, ref, interesting, docs, extra) {
let details = document.createElement("details");
let summary = document.createElement("summary");
details.appendChild(summary);
summary.textContent = name + ": ";
let items = document.createElement("b");
items.textContent = interesting.filter(item => ref[item])
.map(item => item + ": " +
(typeof ref[item] == "function" ? ref[item]() : ref[item]))
.join(", ");
summary.appendChild(items);
let docsEl = document.createElement("a");
docsEl.textContent = "Documentation for " + name + " on MDN";
docsEl.href = docs;
details.appendChild(docsEl);
details.addEventListener("toggle", event => {
if (details.open) {
function dumpInner(parent, ref, n) {
let output = false;
let ul = document.createElement("ul");
let items = [];
for (const item in ref) {
items.push(item);
}
for (const item of items.sort()) {
if (typeof(ref[item]) == "function" && (!extra || !extra.includes(item))) {
continue;
}
let el = document.createElement("li");
el.textContent = item + ": " +
(typeof(ref[item]) == "function" ? ref[item]() : ref[item]);
if (ref[item] && !output) {
output = true;
}
if (typeof(ref[item]) == "object" && n < 4) {
if (ref[item] && ref[item] instanceof Plugin) {
el.textContent = item + ": " + ref[item].name + " (" + ref[item].filename + ")"
} else if (!dumpInner(el, ref[item], n+1)) {
// nothing interesting, drop this too
continue;
}
}
ul.appendChild(el);
}
parent.appendChild(ul);
return output;
}
dumpInner(details, ref, 0);
} else {
details.removeChild(details.querySelector("ul"));
}
});
document.querySelector(selector).appendChild(details);
}
function linkifyHTTP(el) {
let req = el.textContent;
let i = 0;
el.textContent = "";
for (let line of req.replace(/\n$/, '').split('\n')) {
if (i == 0) {
if (line.match(/(\w+)/)) {
let verb = RegExp.$1;
let a = document.createElement("a");
a.href = "https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET";
a.textContent = verb;
el.appendChild(a);
el.appendChild(document.createTextNode(line.substr(verb.length) + "\n"));
} else {
el.appendChild(document.createTextNode(line + "\n"));
}
} else {
if (line.match(/^([-a-zA-Z0-9_]+):/)) {
let header = RegExp.$1;
let a = document.createElement("a");
a.href = "https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/" + header;
a.textContent = header;
el.appendChild(a);
el.appendChild(document.createTextNode(line.substr(header.length) + "\n"));
} else {
el.appendChild(document.createTextNode(line + "\n"));
}
}
i++;
}
}
async function dns(selector) {
let details = document.querySelector(selector);
try {
let result = await fetchDNS("0");
details.textContent = result;
} catch (e) {
details.textContent = e;
}
}
function establishWebRTC(selector) {
if (!window.RTCPeerConnection) {
document.querySelector(selector).textContent = "No WebRTC support.";
return;
}
let foundConn = function(out, desc) {
// Local
if (/ IN IP(\d+) ([^\s]+)/.test(desc.sdp)) {
// Most browsers seem to just send 127.0.0.1 to avoid local leakage now
let protocol = RegExp.$1;
let ip = RegExp.$2;
if (ip != "127.0.0.1" && ip != "::1" && ip != "0.0.0.0") {
out.appendChild(document.createTextNode("Local (internal) address: " + ip));
out.appendChild(document.createElement("br"));
}
}
// Candidates
let re = /a=candidate:\d+ \d+ (\w+) \S+ ((?:\d+\.){3}\d+|[a-f0-9:]+) (\d+)/g;
let match;
let local = false;
while ((match = re.exec(desc.sdp)) !== null) {
let protocol = match[1];
let ip = match[2];
let port = match[3];
if (ip.match(/^(10\.|192\.168\.|172.(1[6789]|2\d|3[01])\.)/)) {
if (!local) {
out.appendChild(document.createTextNode("Local (internal) address: " + ip));
out.appendChild(document.createElement("br"));
local = true;
}
continue;
}
out.appendChild(document.createTextNode("Source IP address: "));
let b = document.createElement("b");
b.textContent = ip;
b.title = desc.sdp;
b.addEventListener("dblclick", e => {
window.getSelection().selectAllChildren(e.srcElement);
e.preventDefault();
});
out.appendChild(b);
out.appendChild(document.createTextNode(" "));
let flag = document.createElement("span");
flag.className = "country";
out.appendChild(flag);
if (!ipDetails[ip]) {
fetchIPDetails(ip).then(details => {
ipDetails[ip] = details;
doIPDetails(selector, ip, ipDetails);
});
} else {
doIPDetails(selector, ip, ipDetails);
}
out.appendChild(document.createElement("br"));
if (port) {
out.appendChild(document.createTextNode("Source port: "));
b = document.createElement("b");
b.textContent = port;
out.appendChild(b);
out.appendChild(document.createElement("br"));
}
if (ip != ipv4 && ip != ipv6) {
out.appendChild(document.createTextNode(
"Warning: IP found via WebRTC differs to HTTP IP, potential leakage!"));
}
}
};
let conn = new RTCPeerConnection({
iceServers: [{urls: ["stun:stun.l.google.com:19302"]}]});
conn.createDataChannel('ip');
let candidate = false;
conn.onicecandidate = e => {
candidate = true;
let out = document.querySelector(selector);
out.textContent = "";
if (conn.pendingLocalDescription) {
foundConn(out, conn.pendingLocalDescription);
} else {
foundConn(out, conn.localDescription);
}
};
conn.onicecandidateerror = e => {
if (candidate) {
return;
}
let out = document.querySelector(selector);
out.textContent = "Error establishing WebRTC connection: " + e.errorText;
};
conn.createOffer({}).then(desc => conn.setLocalDescription(desc));
}
</script>
<script>
var ipv4 = "", ipv6 = "";
{{- if .IPv4 }}
ipv4 = "{{ .IPv4 }}";
{{- else }}
ipv6 = "{{ .IPv6 }}";
{{- end }}
var ipDetails = {{ .Details }};
</script>
<body>
<header>
<div class="topemoji"><a href="/fun">👻</a></div>
<h1>WTF is my <a href="https://en.wikipedia.org/wiki/IP_address">IP address</a>?</h1>
</header>
<article>
<div class="ip">
{{- if .IPv4 }}
You're using <a href="https://en.wikipedia.org/wiki/IPv4">IPv4</a>:
<div class="ipv4" id="ip">{{ .IPv4 }}</div>
{{- else if .IPv6 }}
You're using <a href="https://en.wikipedia.org/wiki/IPv6">IPv6</a>:
<div class="ipv6 dblselect" id="ip">{{ .IPv6 }}</div>
{{- end }}
</div>
<div id="ip-space">
<noscript>
To see the rest of this page correctly please enable JavaScript.
</noscript>
</div>
<div id="extra-ip">
Your browser preferred using {{ if .IPv4 }}IPv4{{else}}IPv6{{end}} but you also have an <span
id="other-ip" class="dblselect"></span>
</div>
<div id="only-ip">
You do not appear to have any {{ if .IPv4 }}IPv6{{else}}IPv4{{end}} connectivity.
</div>
<table class="details-table">
<tr>
{{/* Most people with IPv6 currently also have IPv4, show loading to avoid reflow. */}}
<td id="ipv4-details" class="details">
<h3>IPv4 details</h3>
<span class="country">⏳</span> <span class="city"></span>
<br>
Reverse DNS: <span class="host dblselect">⏳</span>
<br>
<abbr title="Autonomous System">AS</abbr><span class="asn"></span>
↝ <a href="https://bgp.tools/search?q={{.IPv4}}">More details on bgp.tools</a>
</td>
<td id="ipv6-details" class="details {{if .IPv4}}hidden{{end}}">
<h3>IPv6 details</h3>
<span class="country">⏳</span> <span class="city"></span>
<br>
Reverse DNS: <span class="host dblselect">⏳</span>
<br>
<abbr title="Autonomous System">AS</abbr><span class="asn"></span>
↝ <a href="https://bgp.tools/search?q={{.IPv6}}">More details on bgp.tools</a>
</td>
</tr>
</table>
<div class="details">
<h3>Connection details</h3>
Source <abbr title="Transmission Control Protocol, the layer below HTTP">
TCP</abbr> port: <b>{{ .RemoteAddr.Port }}</b><br>
{{ if .TLS }}
<abbr title="Transport Layer Security, the way traffic is encrypted">TLS</abbr> version:
<b title="{{ .TLSCipher }}">{{ .TLS }}</b><br>
{{ end }}
<br>Raw <abbr title="The actual request your browser (or a proxy in-between) sent to this server over Hypertext Transfer Protocol (HTTP)">
HTTP request</abbr>:
<pre id="http-request">{{ .Request }}</pre>
Number of <abbr title="HTTP requests over the same TCP connection due to keep-alive, reload quickly and see this increase, maybe!">
requests</abbr> over this connection: <b>{{ .RequestCount }}</b>
<br>
<script>
linkifyHTTP(document.querySelector("#http-request"));
</script>
</div>
<div class="details">
<h3>Browser details</h3>
<div id="navigator-basic-details"></div>
<script>
dump("#navigator-basic-details", "navigator", window.navigator, ["vendor", "platform", "hardwareConcurrency", "deviceMemory"],
"https://developer.mozilla.org/en-US/docs/Web/API/Navigator");
</script>
<div id="time-details"></div>
<script>
dump('#time-details', 'Date', new Date(), ["toTimeString"],
"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date",
["toString", "toLocaleString", "toTimeString", "toLocaleTimeString"]);
</script>
<div id="screen-details"></div>
<script>
dump("#screen-details", "window.screen", window.screen, ["width", "height"],
"https://developer.mozilla.org/en-US/docs/Web/API/Window/screen");
</script>
<div id="connection-details"></div>
<script>
if (navigator.connection)
dump("#connection-details", "navigator.connection", navigator.connection, ["effectiveType", "rtt", "downlink"],
"https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation");
</script>
<div id="battery-details"></div>
<script>
if (navigator.getBattery)
navigator.getBattery().then(
battery => dump("#battery-details", "navigator.getBattery()", battery, ["charging", "level"],
"https://developer.mozilla.org/en-US/docs/Web/API/Navigator/getBattery"));
</script>
</div>
<div class="details hidden">
<h3>DNS details</h3>
<div id="dns-details">
<small id="dns-loading">Querying your DNS servers...</small>
</div>
<script>
dns("#dns-details");
</script>
</div>
<div class="details">
<h3>WebRTC connection</h3>
<div id="webrtc-details">
<small id="webrtc-loading">Attempting to establish a WebRTC connection
(may result in bypassing some VPNs...)</small>
</div>
<script>
establishWebRTC("#webrtc-details");
</script>
</div>
<div class="details">
<h3>ip.wtf API</h3>
<div id="api-details">
<p>You can query your IP address from the command line with the API:
<pre><code>$ <span class="dblselect">curl ip.wtf</span>
<span id="your-ip">[your IP]</span></code></pre>
<script>
let d = ipDetails["{{ if .IPv4 }}{{.IPv4}}{{ else }}{{.IPv6}}{{ end }}"];
document.querySelector("#your-ip").textContent = d.ip;
</script>
<p>Or in JSON:</p>
<pre><code>$ <span class="dblselect">curl --json "" ip.wtf</span>
<span id="json-output"></span></code></pre>
<script>
document.querySelector("#json-output").textContent = JSON.stringify(d, "", " ");
</script>
<br><a href="/about">More details...</a>
</div>
<script>
</script>
</div>
</article>
<footer>
<ul {{- if .NodeLocation }} title="served by a node in {{.NodeLocation}}"
{{- end }}>
<li><a href="/about">about</a>
<li><a href="https://github.com/dgl/ip.wtf">github</a>
<li><a href="https://ko-fi.com/webgl" id="sponsor">sponsor ☕️</a>
</ul>
</footer>
<script>
(function(ipel) {
let n = 6;
while (ipel.scrollWidth > ipel.clientWidth)
ipel.style.fontSize = (ipel.clientWidth / n++) + "px"
if (ipel.clientHeight < 2)
ipel.style.fontSize = "2em";
})(document.querySelector("#ip"));
function condCheck(x) {
let d = ipDetails["{{ if .IPv4 }}{{.IPv4}}{{ else }}{{.IPv6}}{{ end }}"];
return x.filter(c => c == d.location.country).length;
}
let today = new Date();
let ds = (1+today.getMonth()) + "-" + today.getDate() + "-" + today.getDay() + "-" +
(1+Math.floor(today.getDate() / 7));
const specials = [
[ /^2-14/, "vt.css" ],
[ /^3-17/, "sp.css" ],
[ /^4-22/, "ed.css" ],
[ /^4-25/, "anzac.css", ["AU", "NZ", "CX", "CC", "CK", "NU", "NF", "TK", "TO"] ],
[ /^6-19/, "jt.css" ],
[ /^7-4/, "id.css", ["US"] ],
[ /^7-17/, "emoji.css" ],
[ /^10-\d+-1-2/, "tg.css", ["CA"] ],
[ /^10-3[01]/, "ah.css" ],
[ /^11-5/, "gf.css", ["UK"] ],
[ /^11-11/, "lestweforget.css", ["UK", "US", "CA", "AU", "ZA", "NZ" ] ],
[ /^11-\d+-4-4/, "tg.css", ["US"] ],
[ /^11-\d+-5-4/, "bf.css", ["US", "UK", "CA", "AU", "NZ"] ],
[ /^12-[123]\d/, "xm.css" ],
[ /^12-[23]\d/, "xm2.css" ],
[ /^12-31/, "ny.css" ],
];
for (let s of specials) {
if ((s[0].test(ds) && (!s[2] || condCheck(s[2])))
{{- if .Devel -}}
|| location.hash.match(s[1])
{{- end -}}
) {
var link = document.createElement("link");
link.rel = "stylesheet";
link.type = "text/css";
link.href = "/.static/" + s[1];
document.head.appendChild(link);
}
}
(function(sp) {
let d = new Date;
if (d.getHours() >= 17 && !condCheck(["AF", "BD", "KW", "LY", "MR", "PK", "OM", "PS", "QA", "SA", "SO", "SD", "YE"]))
sp.textContent = "sponsor 🍺";
})(document.querySelector("#sponsor"));
{{ if .IPv4 }}
ipv4details("{{.IPv4}}");
{{ else }}
ipv6details("{{.IPv6}}");
{{ end }}
fetch("//{{ if .IPv4 }}{{ .V6Host }}{{ else }}{{ .V4Host }}{{ end }}", {
headers: {
Accept: "application/json"
}
}).then(r => r.json())
.then(data => {
let ip = data.ip;
// Have other protocol IP address
let other = document.querySelector('#other-ip');
other.textContent = "{{ if .IPv4 }}IPv6{{ else }}IPv4{{ end }} address: "
let ipEl = document.createElement("b");
ipEl.textContent = ip;
other.appendChild(ipEl)
document.querySelector('#extra-ip').style.display = 'block';
document.querySelector('#ip-space').classList.add('hidden');
ipDetails[ip] = data;
if (/:/.test(ip)) {
ipv6details(ip);
ipv6 = ip;
} else {
ipv4details(ip);
ipv4 = ip;
}
})
.catch(error => {
// error => Don't have other protocol.
document.querySelector('#only-ip').style.display = 'block';
document.querySelector('#ip-space').classList.add('hidden');
if (!ipv4) {
// no IPv4 => IPv6 only, hide pre-emptively shown IPv4 cell.
let details = document.querySelector("#ipv4-details");
details.classList.add('hidden');
}
});
for (let el of [...document.querySelectorAll(".dblselect")]) {
el.addEventListener("dblclick", e => {
window.getSelection().selectAllChildren(el);
e.preventDefault();
});
}
</script>
</body>