riteshjs 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/net.js ADDED
@@ -0,0 +1,1380 @@
1
+ /*! ritesh | MIT | Copyright (c) 2026 Jarrod Baumann | bundles xterm.js and ipaddr.js (MIT, see THIRD_PARTY_NOTICES) */
2
+ import { r as __toESM, t as __commonJSMin } from "./rolldown-runtime-Sht-Y2pv.js";
3
+ // src/net/ip.ts
4
+ var import_ipaddr = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module, this$1) => {
5
+ (function(root) {
6
+ "use strict";
7
+ const ipv4Part = "(0?\\d+|0x[a-f0-9]+)";
8
+ const ipv4Regexes = {
9
+ fourOctet: new RegExp(`^${ipv4Part}\\.${ipv4Part}\\.${ipv4Part}\\.${ipv4Part}$`, "i"),
10
+ threeOctet: new RegExp(`^${ipv4Part}\\.${ipv4Part}\\.${ipv4Part}$`, "i"),
11
+ twoOctet: new RegExp(`^${ipv4Part}\\.${ipv4Part}$`, "i"),
12
+ longValue: new RegExp(`^${ipv4Part}$`, "i")
13
+ };
14
+ const octalRegex = new RegExp(`^0[0-7]+$`, "i");
15
+ const hexRegex = new RegExp(`^0x[a-f0-9]+$`, "i");
16
+ const zoneIndex = "%[0-9a-z]{1,}";
17
+ const ipv6Part = "(?:[0-9a-f]+::?)+";
18
+ const ipv6Regexes = {
19
+ zoneIndex: new RegExp(zoneIndex, "i"),
20
+ "native": new RegExp(`^(::)?(${ipv6Part})?([0-9a-f]+)?(::)?(${zoneIndex})?$`, "i"),
21
+ deprecatedTransitional: new RegExp(`^(?:::)(${ipv4Part}\\.${ipv4Part}\\.${ipv4Part}\\.${ipv4Part}(${zoneIndex})?)$`, "i"),
22
+ transitional: new RegExp(`^((?:${ipv6Part})|(?:::)(?:${ipv6Part})?)${ipv4Part}\\.${ipv4Part}\\.${ipv4Part}\\.${ipv4Part}(${zoneIndex})?$`, "i")
23
+ };
24
+ function expandIPv6(string, parts) {
25
+ if (string.indexOf("::") !== string.lastIndexOf("::")) return null;
26
+ let colonCount = 0;
27
+ let lastColon = -1;
28
+ let zoneId = (string.match(ipv6Regexes.zoneIndex) || [])[0];
29
+ let replacement, replacementCount;
30
+ if (zoneId) {
31
+ zoneId = zoneId.substring(1);
32
+ string = string.replace(/%.+$/, "");
33
+ }
34
+ while ((lastColon = string.indexOf(":", lastColon + 1)) >= 0) colonCount++;
35
+ if (string.substr(0, 2) === "::") colonCount--;
36
+ if (string.substr(-2, 2) === "::") colonCount--;
37
+ if (colonCount >= parts) return null;
38
+ replacementCount = parts - colonCount;
39
+ replacement = ":";
40
+ while (replacementCount--) replacement += "0:";
41
+ string = string.replace("::", replacement);
42
+ if (string[0] === ":") string = string.slice(1);
43
+ if (string[string.length - 1] === ":") string = string.slice(0, -1);
44
+ parts = (function() {
45
+ const ref = string.split(":");
46
+ const results = [];
47
+ for (let i = 0; i < ref.length; i++) results.push(ref[i].length > 4 ? NaN : parseInt(ref[i], 16));
48
+ return results;
49
+ })();
50
+ return {
51
+ parts,
52
+ zoneId
53
+ };
54
+ }
55
+ function matchCIDR(first, second, partSize, cidrBits) {
56
+ if (first.length !== second.length) throw new Error("ipaddr: cannot match CIDR for objects with different lengths");
57
+ let part = 0;
58
+ let shift;
59
+ while (cidrBits > 0) {
60
+ shift = partSize - cidrBits;
61
+ if (shift < 0) shift = 0;
62
+ if (first[part] >> shift !== second[part] >> shift) return false;
63
+ cidrBits -= partSize;
64
+ part += 1;
65
+ }
66
+ return true;
67
+ }
68
+ function parseIntAuto(string) {
69
+ if (hexRegex.test(string)) return parseInt(string, 16);
70
+ if (string[0] === "0" && !isNaN(parseInt(string[1], 10))) {
71
+ if (octalRegex.test(string)) return parseInt(string, 8);
72
+ throw new Error(`ipaddr: cannot parse ${string} as octal`);
73
+ }
74
+ return parseInt(string, 10);
75
+ }
76
+ function padPart(part, length) {
77
+ while (part.length < length) part = `0${part}`;
78
+ return part;
79
+ }
80
+ const ipaddr = {};
81
+ ipaddr.IPv4 = (function() {
82
+ function IPv4(octets) {
83
+ if (octets.length !== 4) throw new Error("ipaddr: ipv4 octet count should be 4");
84
+ let i, octet;
85
+ for (i = 0; i < octets.length; i++) {
86
+ octet = octets[i];
87
+ if (!(0 <= octet && octet <= 255)) throw new Error("ipaddr: ipv4 octet should fit in 8 bits");
88
+ }
89
+ this.octets = octets;
90
+ }
91
+ IPv4.prototype.SpecialRanges = {
92
+ unspecified: [[new IPv4([
93
+ 0,
94
+ 0,
95
+ 0,
96
+ 0
97
+ ]), 8]],
98
+ broadcast: [[new IPv4([
99
+ 255,
100
+ 255,
101
+ 255,
102
+ 255
103
+ ]), 32]],
104
+ multicast: [[new IPv4([
105
+ 224,
106
+ 0,
107
+ 0,
108
+ 0
109
+ ]), 4]],
110
+ linkLocal: [[new IPv4([
111
+ 169,
112
+ 254,
113
+ 0,
114
+ 0
115
+ ]), 16]],
116
+ loopback: [[new IPv4([
117
+ 127,
118
+ 0,
119
+ 0,
120
+ 0
121
+ ]), 8]],
122
+ carrierGradeNat: [[new IPv4([
123
+ 100,
124
+ 64,
125
+ 0,
126
+ 0
127
+ ]), 10]],
128
+ "private": [
129
+ [new IPv4([
130
+ 10,
131
+ 0,
132
+ 0,
133
+ 0
134
+ ]), 8],
135
+ [new IPv4([
136
+ 172,
137
+ 16,
138
+ 0,
139
+ 0
140
+ ]), 12],
141
+ [new IPv4([
142
+ 192,
143
+ 168,
144
+ 0,
145
+ 0
146
+ ]), 16]
147
+ ],
148
+ reserved: [
149
+ [new IPv4([
150
+ 192,
151
+ 0,
152
+ 0,
153
+ 0
154
+ ]), 24],
155
+ [new IPv4([
156
+ 192,
157
+ 0,
158
+ 2,
159
+ 0
160
+ ]), 24],
161
+ [new IPv4([
162
+ 192,
163
+ 88,
164
+ 99,
165
+ 0
166
+ ]), 24],
167
+ [new IPv4([
168
+ 198,
169
+ 18,
170
+ 0,
171
+ 0
172
+ ]), 15],
173
+ [new IPv4([
174
+ 198,
175
+ 51,
176
+ 100,
177
+ 0
178
+ ]), 24],
179
+ [new IPv4([
180
+ 203,
181
+ 0,
182
+ 113,
183
+ 0
184
+ ]), 24],
185
+ [new IPv4([
186
+ 240,
187
+ 0,
188
+ 0,
189
+ 0
190
+ ]), 4]
191
+ ],
192
+ as112: [[new IPv4([
193
+ 192,
194
+ 175,
195
+ 48,
196
+ 0
197
+ ]), 24], [new IPv4([
198
+ 192,
199
+ 31,
200
+ 196,
201
+ 0
202
+ ]), 24]],
203
+ amt: [[new IPv4([
204
+ 192,
205
+ 52,
206
+ 193,
207
+ 0
208
+ ]), 24]]
209
+ };
210
+ IPv4.prototype.kind = function() {
211
+ return "ipv4";
212
+ };
213
+ IPv4.prototype.match = function(other, cidrRange) {
214
+ let ref;
215
+ if (cidrRange === void 0) {
216
+ ref = other;
217
+ other = ref[0];
218
+ cidrRange = ref[1];
219
+ }
220
+ if (other.kind() !== "ipv4") throw new Error("ipaddr: cannot match ipv4 address with non-ipv4 one");
221
+ return matchCIDR(this.octets, other.octets, 8, cidrRange);
222
+ };
223
+ IPv4.prototype.prefixLengthFromSubnetMask = function() {
224
+ let cidr = 0;
225
+ let stop = false;
226
+ const zerotable = {
227
+ 0: 8,
228
+ 128: 7,
229
+ 192: 6,
230
+ 224: 5,
231
+ 240: 4,
232
+ 248: 3,
233
+ 252: 2,
234
+ 254: 1,
235
+ 255: 0
236
+ };
237
+ let i, octet, zeros;
238
+ for (i = 3; i >= 0; i -= 1) {
239
+ octet = this.octets[i];
240
+ if (octet in zerotable) {
241
+ zeros = zerotable[octet];
242
+ if (stop && zeros !== 0) return null;
243
+ if (zeros !== 8) stop = true;
244
+ cidr += zeros;
245
+ } else return null;
246
+ }
247
+ return 32 - cidr;
248
+ };
249
+ IPv4.prototype.range = function() {
250
+ return ipaddr.subnetMatch(this, this.SpecialRanges);
251
+ };
252
+ IPv4.prototype.toByteArray = function() {
253
+ return this.octets.slice(0);
254
+ };
255
+ IPv4.prototype.toIPv4MappedAddress = function() {
256
+ return ipaddr.IPv6.parse(`::ffff:${this.toString()}`);
257
+ };
258
+ IPv4.prototype.toNormalizedString = function() {
259
+ return this.toString();
260
+ };
261
+ IPv4.prototype.toString = function() {
262
+ return this.octets.join(".");
263
+ };
264
+ return IPv4;
265
+ })();
266
+ ipaddr.IPv4.broadcastAddressFromCIDR = function(string) {
267
+ try {
268
+ const cidr = this.parseCIDR(string);
269
+ const ipInterfaceOctets = cidr[0].toByteArray();
270
+ const subnetMaskOctets = this.subnetMaskFromPrefixLength(cidr[1]).toByteArray();
271
+ const octets = [];
272
+ let i = 0;
273
+ while (i < 4) {
274
+ octets.push(parseInt(ipInterfaceOctets[i], 10) | parseInt(subnetMaskOctets[i], 10) ^ 255);
275
+ i++;
276
+ }
277
+ return new this(octets);
278
+ } catch (e) {
279
+ throw new Error("ipaddr: the address does not have IPv4 CIDR format", { cause: e });
280
+ }
281
+ };
282
+ ipaddr.IPv4.isIPv4 = function(string) {
283
+ return this.parser(string) !== null;
284
+ };
285
+ ipaddr.IPv4.isValid = function(string) {
286
+ try {
287
+ new this(this.parser(string));
288
+ return true;
289
+ } catch {
290
+ return false;
291
+ }
292
+ };
293
+ ipaddr.IPv4.isValidCIDR = function(string) {
294
+ try {
295
+ this.parseCIDR(string);
296
+ return true;
297
+ } catch {
298
+ return false;
299
+ }
300
+ };
301
+ ipaddr.IPv4.isValidFourPartDecimal = function(string) {
302
+ if (ipaddr.IPv4.isValid(string) && string.match(/^(0|[1-9]\d*)(\.(0|[1-9]\d*)){3}$/)) return true;
303
+ else return false;
304
+ };
305
+ ipaddr.IPv4.isValidCIDRFourPartDecimal = function(string) {
306
+ const match = string.match(/^(.+)\/(\d+)$/);
307
+ if (!ipaddr.IPv4.isValidCIDR(string) || !match) return false;
308
+ return ipaddr.IPv4.isValidFourPartDecimal(match[1]);
309
+ };
310
+ ipaddr.IPv4.networkAddressFromCIDR = function(string) {
311
+ let cidr, i, ipInterfaceOctets, octets, subnetMaskOctets;
312
+ try {
313
+ cidr = this.parseCIDR(string);
314
+ ipInterfaceOctets = cidr[0].toByteArray();
315
+ subnetMaskOctets = this.subnetMaskFromPrefixLength(cidr[1]).toByteArray();
316
+ octets = [];
317
+ i = 0;
318
+ while (i < 4) {
319
+ octets.push(parseInt(ipInterfaceOctets[i], 10) & parseInt(subnetMaskOctets[i], 10));
320
+ i++;
321
+ }
322
+ return new this(octets);
323
+ } catch (e) {
324
+ throw new Error("ipaddr: the address does not have IPv4 CIDR format", { cause: e });
325
+ }
326
+ };
327
+ ipaddr.IPv4.parse = function(string) {
328
+ const parts = this.parser(string);
329
+ if (parts === null) throw new Error("ipaddr: string is not formatted like an IPv4 Address");
330
+ return new this(parts);
331
+ };
332
+ ipaddr.IPv4.parseCIDR = function(string) {
333
+ let match;
334
+ if (match = string.match(/^(.+)\/(\d+)$/)) {
335
+ const maskLength = parseInt(match[2]);
336
+ if (maskLength >= 0 && maskLength <= 32) {
337
+ const parsed = [this.parse(match[1]), maskLength];
338
+ Object.defineProperty(parsed, "toString", { value: function() {
339
+ return this.join("/");
340
+ } });
341
+ return parsed;
342
+ }
343
+ }
344
+ throw new Error("ipaddr: string is not formatted like an IPv4 CIDR range");
345
+ };
346
+ ipaddr.IPv4.parser = function(string) {
347
+ let match, part, value;
348
+ if (match = string.match(ipv4Regexes.fourOctet)) return (function() {
349
+ const ref = match.slice(1, 6);
350
+ const results = [];
351
+ for (let i = 0; i < ref.length; i++) {
352
+ part = ref[i];
353
+ results.push(parseIntAuto(part));
354
+ }
355
+ return results;
356
+ })();
357
+ else if (match = string.match(ipv4Regexes.longValue)) {
358
+ value = parseIntAuto(match[1]);
359
+ if (value > 0xffffffff || value < 0) throw new Error("ipaddr: address outside defined range");
360
+ return (function() {
361
+ const results = [];
362
+ let shift = 0;
363
+ for (; shift <= 24; shift += 8) results.push(value >> shift & 255);
364
+ return results;
365
+ })().reverse();
366
+ } else if (match = string.match(ipv4Regexes.twoOctet)) return (function() {
367
+ const ref = match.slice(1, 4);
368
+ const results = [];
369
+ value = parseIntAuto(ref[1]);
370
+ if (value > 0xffffff || value < 0) throw new Error("ipaddr: address outside defined range");
371
+ results.push(parseIntAuto(ref[0]));
372
+ results.push(value >> 16 & 255);
373
+ results.push(value >> 8 & 255);
374
+ results.push(value & 255);
375
+ return results;
376
+ })();
377
+ else if (match = string.match(ipv4Regexes.threeOctet)) return (function() {
378
+ const ref = match.slice(1, 5);
379
+ const results = [];
380
+ value = parseIntAuto(ref[2]);
381
+ if (value > 65535 || value < 0) throw new Error("ipaddr: address outside defined range");
382
+ results.push(parseIntAuto(ref[0]));
383
+ results.push(parseIntAuto(ref[1]));
384
+ results.push(value >> 8 & 255);
385
+ results.push(value & 255);
386
+ return results;
387
+ })();
388
+ else return null;
389
+ };
390
+ ipaddr.IPv4.subnetMaskFromPrefixLength = function(prefix) {
391
+ prefix = parseInt(prefix);
392
+ if (Number.isNaN(prefix) || prefix < 0 || prefix > 32) throw new Error("ipaddr: invalid IPv4 prefix length");
393
+ const octets = [
394
+ 0,
395
+ 0,
396
+ 0,
397
+ 0
398
+ ];
399
+ let j = 0;
400
+ const filledOctetCount = Math.floor(prefix / 8);
401
+ while (j < filledOctetCount) {
402
+ octets[j] = 255;
403
+ j++;
404
+ }
405
+ if (filledOctetCount < 4) octets[filledOctetCount] = Math.pow(2, prefix % 8) - 1 << 8 - prefix % 8;
406
+ return new this(octets);
407
+ };
408
+ ipaddr.IPv6 = (function() {
409
+ function IPv6(parts, zoneId) {
410
+ let i, part;
411
+ if (parts.length === 16) {
412
+ this.parts = [];
413
+ for (i = 0; i <= 14; i += 2) this.parts.push(parts[i] << 8 | parts[i + 1]);
414
+ } else if (parts.length === 8) this.parts = parts;
415
+ else throw new Error("ipaddr: ipv6 part count should be 8 or 16");
416
+ for (i = 0; i < this.parts.length; i++) {
417
+ part = this.parts[i];
418
+ if (!(0 <= part && part <= 65535)) throw new Error("ipaddr: ipv6 part should fit in 16 bits");
419
+ }
420
+ if (zoneId) this.zoneId = zoneId;
421
+ }
422
+ IPv6.prototype.SpecialRanges = {
423
+ unspecified: [new IPv6([
424
+ 0,
425
+ 0,
426
+ 0,
427
+ 0,
428
+ 0,
429
+ 0,
430
+ 0,
431
+ 0
432
+ ]), 128],
433
+ linkLocal: [new IPv6([
434
+ 65152,
435
+ 0,
436
+ 0,
437
+ 0,
438
+ 0,
439
+ 0,
440
+ 0,
441
+ 0
442
+ ]), 10],
443
+ multicast: [new IPv6([
444
+ 65280,
445
+ 0,
446
+ 0,
447
+ 0,
448
+ 0,
449
+ 0,
450
+ 0,
451
+ 0
452
+ ]), 8],
453
+ loopback: [new IPv6([
454
+ 0,
455
+ 0,
456
+ 0,
457
+ 0,
458
+ 0,
459
+ 0,
460
+ 0,
461
+ 1
462
+ ]), 128],
463
+ uniqueLocal: [new IPv6([
464
+ 64512,
465
+ 0,
466
+ 0,
467
+ 0,
468
+ 0,
469
+ 0,
470
+ 0,
471
+ 0
472
+ ]), 7],
473
+ ipv4Mapped: [new IPv6([
474
+ 0,
475
+ 0,
476
+ 0,
477
+ 0,
478
+ 0,
479
+ 65535,
480
+ 0,
481
+ 0
482
+ ]), 96],
483
+ deprecatedSiteLocal: [new IPv6([
484
+ 65216,
485
+ 0,
486
+ 0,
487
+ 0,
488
+ 0,
489
+ 0,
490
+ 0,
491
+ 0
492
+ ]), 10],
493
+ discard: [new IPv6([
494
+ 256,
495
+ 0,
496
+ 0,
497
+ 0,
498
+ 0,
499
+ 0,
500
+ 0,
501
+ 0
502
+ ]), 64],
503
+ rfc6145: [new IPv6([
504
+ 0,
505
+ 0,
506
+ 0,
507
+ 0,
508
+ 65535,
509
+ 0,
510
+ 0,
511
+ 0
512
+ ]), 96],
513
+ rfc6052: [[new IPv6([
514
+ 100,
515
+ 65435,
516
+ 0,
517
+ 0,
518
+ 0,
519
+ 0,
520
+ 0,
521
+ 0
522
+ ]), 96], [new IPv6([
523
+ 100,
524
+ 65435,
525
+ 1,
526
+ 0,
527
+ 0,
528
+ 0,
529
+ 0,
530
+ 0
531
+ ]), 48]],
532
+ "6to4": [new IPv6([
533
+ 8194,
534
+ 0,
535
+ 0,
536
+ 0,
537
+ 0,
538
+ 0,
539
+ 0,
540
+ 0
541
+ ]), 16],
542
+ teredo: [new IPv6([
543
+ 8193,
544
+ 0,
545
+ 0,
546
+ 0,
547
+ 0,
548
+ 0,
549
+ 0,
550
+ 0
551
+ ]), 32],
552
+ benchmarking: [new IPv6([
553
+ 8193,
554
+ 2,
555
+ 0,
556
+ 0,
557
+ 0,
558
+ 0,
559
+ 0,
560
+ 0
561
+ ]), 48],
562
+ amt: [new IPv6([
563
+ 8193,
564
+ 3,
565
+ 0,
566
+ 0,
567
+ 0,
568
+ 0,
569
+ 0,
570
+ 0
571
+ ]), 32],
572
+ as112v6: [[new IPv6([
573
+ 8193,
574
+ 4,
575
+ 274,
576
+ 0,
577
+ 0,
578
+ 0,
579
+ 0,
580
+ 0
581
+ ]), 48], [new IPv6([
582
+ 9760,
583
+ 79,
584
+ 32768,
585
+ 0,
586
+ 0,
587
+ 0,
588
+ 0,
589
+ 0
590
+ ]), 48]],
591
+ deprecatedOrchid: [new IPv6([
592
+ 8193,
593
+ 16,
594
+ 0,
595
+ 0,
596
+ 0,
597
+ 0,
598
+ 0,
599
+ 0
600
+ ]), 28],
601
+ orchid2: [new IPv6([
602
+ 8193,
603
+ 32,
604
+ 0,
605
+ 0,
606
+ 0,
607
+ 0,
608
+ 0,
609
+ 0
610
+ ]), 28],
611
+ droneRemoteIdProtocolEntityTags: [new IPv6([
612
+ 8193,
613
+ 48,
614
+ 0,
615
+ 0,
616
+ 0,
617
+ 0,
618
+ 0,
619
+ 0
620
+ ]), 28],
621
+ segmentRouting: [new IPv6([
622
+ 24320,
623
+ 0,
624
+ 0,
625
+ 0,
626
+ 0,
627
+ 0,
628
+ 0,
629
+ 0
630
+ ]), 16],
631
+ reserved: [
632
+ [new IPv6([
633
+ 8193,
634
+ 0,
635
+ 0,
636
+ 0,
637
+ 0,
638
+ 0,
639
+ 0,
640
+ 0
641
+ ]), 23],
642
+ [new IPv6([
643
+ 8193,
644
+ 3512,
645
+ 0,
646
+ 0,
647
+ 0,
648
+ 0,
649
+ 0,
650
+ 0
651
+ ]), 32],
652
+ [new IPv6([
653
+ 16383,
654
+ 0,
655
+ 0,
656
+ 0,
657
+ 0,
658
+ 0,
659
+ 0,
660
+ 0
661
+ ]), 20]
662
+ ]
663
+ };
664
+ IPv6.prototype.isIPv4MappedAddress = function() {
665
+ return this.range() === "ipv4Mapped";
666
+ };
667
+ IPv6.prototype.kind = function() {
668
+ return "ipv6";
669
+ };
670
+ IPv6.prototype.match = function(other, cidrRange) {
671
+ let ref;
672
+ if (cidrRange === void 0) {
673
+ ref = other;
674
+ other = ref[0];
675
+ cidrRange = ref[1];
676
+ }
677
+ if (other.kind() !== "ipv6") throw new Error("ipaddr: cannot match ipv6 address with non-ipv6 one");
678
+ return matchCIDR(this.parts, other.parts, 16, cidrRange);
679
+ };
680
+ IPv6.prototype.prefixLengthFromSubnetMask = function() {
681
+ let cidr = 0;
682
+ let stop = false;
683
+ const zerotable = {
684
+ 0: 16,
685
+ 32768: 15,
686
+ 49152: 14,
687
+ 57344: 13,
688
+ 61440: 12,
689
+ 63488: 11,
690
+ 64512: 10,
691
+ 65024: 9,
692
+ 65280: 8,
693
+ 65408: 7,
694
+ 65472: 6,
695
+ 65504: 5,
696
+ 65520: 4,
697
+ 65528: 3,
698
+ 65532: 2,
699
+ 65534: 1,
700
+ 65535: 0
701
+ };
702
+ let part, zeros;
703
+ for (let i = 7; i >= 0; i -= 1) {
704
+ part = this.parts[i];
705
+ if (part in zerotable) {
706
+ zeros = zerotable[part];
707
+ if (stop && zeros !== 0) return null;
708
+ if (zeros !== 16) stop = true;
709
+ cidr += zeros;
710
+ } else return null;
711
+ }
712
+ return 128 - cidr;
713
+ };
714
+ IPv6.prototype.range = function() {
715
+ return ipaddr.subnetMatch(this, this.SpecialRanges);
716
+ };
717
+ IPv6.prototype.toByteArray = function() {
718
+ let part;
719
+ const bytes = [];
720
+ const ref = this.parts;
721
+ for (let i = 0; i < ref.length; i++) {
722
+ part = ref[i];
723
+ bytes.push(part >> 8);
724
+ bytes.push(part & 255);
725
+ }
726
+ return bytes;
727
+ };
728
+ IPv6.prototype.toFixedLengthString = function() {
729
+ const addr = (function() {
730
+ const results = [];
731
+ for (let i = 0; i < this.parts.length; i++) results.push(padPart(this.parts[i].toString(16), 4));
732
+ return results;
733
+ }).call(this).join(":");
734
+ let suffix = "";
735
+ if (this.zoneId) suffix = `%${this.zoneId}`;
736
+ return addr + suffix;
737
+ };
738
+ IPv6.prototype.toIPv4Address = function() {
739
+ if (!this.isIPv4MappedAddress()) throw new Error("ipaddr: trying to convert a generic ipv6 address to ipv4");
740
+ const ref = this.parts.slice(-2);
741
+ const high = ref[0];
742
+ const low = ref[1];
743
+ return new ipaddr.IPv4([
744
+ high >> 8,
745
+ high & 255,
746
+ low >> 8,
747
+ low & 255
748
+ ]);
749
+ };
750
+ IPv6.prototype.toNormalizedString = function() {
751
+ const addr = (function() {
752
+ const results = [];
753
+ for (let i = 0; i < this.parts.length; i++) results.push(this.parts[i].toString(16));
754
+ return results;
755
+ }).call(this).join(":");
756
+ let suffix = "";
757
+ if (this.zoneId) suffix = `%${this.zoneId}`;
758
+ return addr + suffix;
759
+ };
760
+ IPv6.prototype.toRFC5952String = function() {
761
+ const regex = /((^|:)(0(:|$)){2,})/g;
762
+ let suffix = "";
763
+ if (this.zoneId) suffix = `%${this.zoneId}`;
764
+ const normalized = this.toNormalizedString();
765
+ const string = normalized.slice(0, normalized.length - suffix.length);
766
+ let bestMatchIndex = 0;
767
+ let bestMatchLength = -1;
768
+ let bestMatchGroups = -1;
769
+ let match;
770
+ while (match = regex.exec(string)) {
771
+ const groups = (match[0].match(/0/g) || []).length;
772
+ if (groups > bestMatchGroups) {
773
+ bestMatchGroups = groups;
774
+ bestMatchIndex = match.index;
775
+ bestMatchLength = match[0].length;
776
+ }
777
+ }
778
+ if (bestMatchLength < 0) return string + suffix;
779
+ return `${string.substring(0, bestMatchIndex)}::${string.substring(bestMatchIndex + bestMatchLength)}${suffix}`;
780
+ };
781
+ IPv6.prototype.toString = function() {
782
+ return this.toRFC5952String();
783
+ };
784
+ return IPv6;
785
+ })();
786
+ ipaddr.IPv6.broadcastAddressFromCIDR = function(string) {
787
+ try {
788
+ const cidr = this.parseCIDR(string);
789
+ const ipInterfaceOctets = cidr[0].toByteArray();
790
+ const subnetMaskOctets = this.subnetMaskFromPrefixLength(cidr[1]).toByteArray();
791
+ const octets = [];
792
+ let i = 0;
793
+ while (i < 16) {
794
+ octets.push(parseInt(ipInterfaceOctets[i], 10) | parseInt(subnetMaskOctets[i], 10) ^ 255);
795
+ i++;
796
+ }
797
+ return new this(octets);
798
+ } catch (e) {
799
+ throw new Error("ipaddr: the address does not have IPv6 CIDR format", { cause: e });
800
+ }
801
+ };
802
+ ipaddr.IPv6.isIPv6 = function(string) {
803
+ return this.parser(string) !== null;
804
+ };
805
+ ipaddr.IPv6.isValid = function(string) {
806
+ if (typeof string === "string" && string.indexOf(":") === -1) return false;
807
+ try {
808
+ const addr = this.parser(string);
809
+ new this(addr.parts, addr.zoneId);
810
+ return true;
811
+ } catch {
812
+ return false;
813
+ }
814
+ };
815
+ ipaddr.IPv6.isValidCIDR = function(string) {
816
+ if (typeof string === "string" && string.indexOf(":") === -1) return false;
817
+ try {
818
+ this.parseCIDR(string);
819
+ return true;
820
+ } catch {
821
+ return false;
822
+ }
823
+ };
824
+ ipaddr.IPv6.networkAddressFromCIDR = function(string) {
825
+ let cidr, i, ipInterfaceOctets, octets, subnetMaskOctets;
826
+ try {
827
+ cidr = this.parseCIDR(string);
828
+ ipInterfaceOctets = cidr[0].toByteArray();
829
+ subnetMaskOctets = this.subnetMaskFromPrefixLength(cidr[1]).toByteArray();
830
+ octets = [];
831
+ i = 0;
832
+ while (i < 16) {
833
+ octets.push(parseInt(ipInterfaceOctets[i], 10) & parseInt(subnetMaskOctets[i], 10));
834
+ i++;
835
+ }
836
+ return new this(octets);
837
+ } catch (e) {
838
+ throw new Error("ipaddr: the address does not have IPv6 CIDR format", { cause: e });
839
+ }
840
+ };
841
+ ipaddr.IPv6.parse = function(string) {
842
+ const addr = this.parser(string);
843
+ if (addr === null) throw new Error("ipaddr: string is not formatted like an IPv6 Address");
844
+ return new this(addr.parts, addr.zoneId);
845
+ };
846
+ ipaddr.IPv6.parseCIDR = function(string) {
847
+ let maskLength, match, parsed;
848
+ if (match = string.match(/^(.+)\/(\d+)$/)) {
849
+ maskLength = parseInt(match[2]);
850
+ if (maskLength >= 0 && maskLength <= 128) {
851
+ parsed = [this.parse(match[1]), maskLength];
852
+ Object.defineProperty(parsed, "toString", { value: function() {
853
+ return this.join("/");
854
+ } });
855
+ return parsed;
856
+ }
857
+ }
858
+ throw new Error("ipaddr: string is not formatted like an IPv6 CIDR range");
859
+ };
860
+ ipaddr.IPv6.parser = function(string) {
861
+ let addr, i, match, octet, octets, zoneId;
862
+ if (match = string.match(ipv6Regexes.deprecatedTransitional)) return this.parser(`::ffff:${match[1]}`);
863
+ if (ipv6Regexes.native.test(string)) return expandIPv6(string, 8);
864
+ if (match = string.match(ipv6Regexes.transitional)) {
865
+ zoneId = match[6] || "";
866
+ addr = match[1];
867
+ if (!match[1].endsWith("::")) addr = addr.slice(0, -1);
868
+ addr = expandIPv6(addr + zoneId, 6);
869
+ if (addr && addr.parts) {
870
+ octets = [
871
+ parseInt(match[2]),
872
+ parseInt(match[3]),
873
+ parseInt(match[4]),
874
+ parseInt(match[5])
875
+ ];
876
+ for (i = 0; i < octets.length; i++) {
877
+ octet = octets[i];
878
+ if (!(0 <= octet && octet <= 255)) return null;
879
+ }
880
+ addr.parts.push(octets[0] << 8 | octets[1]);
881
+ addr.parts.push(octets[2] << 8 | octets[3]);
882
+ return {
883
+ parts: addr.parts,
884
+ zoneId: addr.zoneId
885
+ };
886
+ }
887
+ }
888
+ return null;
889
+ };
890
+ ipaddr.IPv6.subnetMaskFromPrefixLength = function(prefix) {
891
+ prefix = parseInt(prefix);
892
+ if (Number.isNaN(prefix) || prefix < 0 || prefix > 128) throw new Error("ipaddr: invalid IPv6 prefix length");
893
+ const octets = [
894
+ 0,
895
+ 0,
896
+ 0,
897
+ 0,
898
+ 0,
899
+ 0,
900
+ 0,
901
+ 0,
902
+ 0,
903
+ 0,
904
+ 0,
905
+ 0,
906
+ 0,
907
+ 0,
908
+ 0,
909
+ 0
910
+ ];
911
+ let j = 0;
912
+ const filledOctetCount = Math.floor(prefix / 8);
913
+ while (j < filledOctetCount) {
914
+ octets[j] = 255;
915
+ j++;
916
+ }
917
+ if (filledOctetCount < 16) octets[filledOctetCount] = Math.pow(2, prefix % 8) - 1 << 8 - prefix % 8;
918
+ return new this(octets);
919
+ };
920
+ ipaddr.fromByteArray = function(bytes) {
921
+ const length = bytes.length;
922
+ if (length === 4) return new ipaddr.IPv4(bytes);
923
+ else if (length === 16) return new ipaddr.IPv6(bytes);
924
+ else throw new Error("ipaddr: the binary input is neither an IPv6 nor IPv4 address");
925
+ };
926
+ ipaddr.isValid = function(string) {
927
+ return ipaddr.IPv6.isValid(string) || ipaddr.IPv4.isValid(string);
928
+ };
929
+ ipaddr.isValidCIDR = function(string) {
930
+ return ipaddr.IPv6.isValidCIDR(string) || ipaddr.IPv4.isValidCIDR(string);
931
+ };
932
+ ipaddr.parse = function(string) {
933
+ if (ipaddr.IPv6.isValid(string)) return ipaddr.IPv6.parse(string);
934
+ else if (ipaddr.IPv4.isValid(string)) return ipaddr.IPv4.parse(string);
935
+ else throw new Error("ipaddr: the address has neither IPv6 nor IPv4 format");
936
+ };
937
+ ipaddr.parseCIDR = function(string) {
938
+ try {
939
+ return ipaddr.IPv6.parseCIDR(string);
940
+ } catch {
941
+ try {
942
+ return ipaddr.IPv4.parseCIDR(string);
943
+ } catch (e) {
944
+ throw new Error("ipaddr: the address has neither IPv6 nor IPv4 CIDR format", { cause: e });
945
+ }
946
+ }
947
+ };
948
+ ipaddr.process = function(string) {
949
+ const addr = this.parse(string);
950
+ if (addr.kind() === "ipv6" && addr.isIPv4MappedAddress()) return addr.toIPv4Address();
951
+ else return addr;
952
+ };
953
+ ipaddr.subnetMatch = function(address, rangeList, defaultName) {
954
+ let i, rangeName, rangeSubnets, subnet;
955
+ if (defaultName === void 0 || defaultName === null) defaultName = "unicast";
956
+ for (rangeName in rangeList) if (Object.prototype.hasOwnProperty.call(rangeList, rangeName)) {
957
+ rangeSubnets = rangeList[rangeName];
958
+ if (rangeSubnets[0] && !(rangeSubnets[0] instanceof Array)) rangeSubnets = [rangeSubnets];
959
+ for (i = 0; i < rangeSubnets.length; i++) {
960
+ subnet = rangeSubnets[i];
961
+ if (address.kind() === subnet[0].kind() && address.match.apply(address, subnet)) return rangeName;
962
+ }
963
+ }
964
+ return defaultName;
965
+ };
966
+ if (typeof module !== "undefined" && module.exports) module.exports = ipaddr;
967
+ else root.ipaddr = ipaddr;
968
+ })(this$1);
969
+ })))(), 1);
970
+ function parseAddress(text) {
971
+ const [addr = "", prefixText, extra] = text.split("/");
972
+ if (extra !== void 0) return `not an address: ${text}`;
973
+ if (addr.includes("%")) return "zone ids are not taken";
974
+ let parsed;
975
+ if (addr.includes(":")) {
976
+ if (!import_ipaddr.default.IPv6.isValid(addr)) return `not an address: ${addr}`;
977
+ const tail = addr.slice(addr.lastIndexOf(":") + 1);
978
+ if (tail.includes(".") && !import_ipaddr.default.IPv4.isValidFourPartDecimal(tail)) return `not an address: ${addr} (IPv4 is four decimal parts)`;
979
+ parsed = import_ipaddr.default.IPv6.parse(addr);
980
+ } else {
981
+ if (!import_ipaddr.default.IPv4.isValidFourPartDecimal(addr)) return `not an address: ${addr} (IPv4 is four decimal parts)`;
982
+ parsed = import_ipaddr.default.IPv4.parse(addr);
983
+ }
984
+ const family = parsed.kind() === "ipv4" ? "ipv4" : "ipv6";
985
+ const bits = family === "ipv4" ? 32 : 128;
986
+ let prefix = bits;
987
+ if (prefixText !== void 0) {
988
+ if (!/^(0|[1-9]\d{0,2})$/.test(prefixText) || Number(prefixText) > bits) return `not a prefix: /${prefixText}`;
989
+ prefix = Number(prefixText);
990
+ }
991
+ return {
992
+ family,
993
+ bits,
994
+ value: toBigInt(parsed.toByteArray()),
995
+ prefix,
996
+ cidr: prefixText !== void 0,
997
+ range: rangeName(parsed.range())
998
+ };
999
+ }
1000
+ function toBigInt(bytes) {
1001
+ return bytes.reduce((n, b) => n << 8n | BigInt(b), 0n);
1002
+ }
1003
+ function format(family, value) {
1004
+ const count = family === "ipv4" ? 4 : 16;
1005
+ const bytes = [];
1006
+ for (let i = count - 1; i >= 0; i--) bytes.push(Number(value >> BigInt(i * 8) & 255n));
1007
+ return import_ipaddr.default.fromByteArray(bytes).toString();
1008
+ }
1009
+ const RANGES = {
1010
+ unicast: "global",
1011
+ private: "private",
1012
+ loopback: "loopback",
1013
+ linkLocal: "link-local",
1014
+ carrierGradeNat: "carrier-grade NAT",
1015
+ multicast: "multicast",
1016
+ reserved: "reserved (documentation or future use)",
1017
+ broadcast: "broadcast",
1018
+ unspecified: "unspecified",
1019
+ uniqueLocal: "unique local",
1020
+ ipv4Mapped: "IPv4-mapped"
1021
+ };
1022
+ function rangeName(r) {
1023
+ return RANGES[r] ?? r;
1024
+ }
1025
+ function network(p) {
1026
+ const hostBits = BigInt(p.bits - p.prefix);
1027
+ const size = 1n << hostBits;
1028
+ const network = p.value >> hostBits << hostBits;
1029
+ return {
1030
+ network,
1031
+ last: network + size - 1n,
1032
+ size
1033
+ };
1034
+ }
1035
+ function mask(p) {
1036
+ return (1n << BigInt(p.bits)) - 1n ^ (1n << BigInt(p.bits - p.prefix)) - 1n;
1037
+ }
1038
+ function hosts(p) {
1039
+ const n = network(p);
1040
+ if (p.family === "ipv6" || p.prefix >= 31) return {
1041
+ first: n.network,
1042
+ last: n.last,
1043
+ count: n.size
1044
+ };
1045
+ return {
1046
+ first: n.network + 1n,
1047
+ last: n.last - 1n,
1048
+ count: n.size - 2n
1049
+ };
1050
+ }
1051
+ // src/net/commands.ts
1052
+ function printable(s) {
1053
+ let out = "";
1054
+ for (const ch of s) {
1055
+ const c = ch.codePointAt(0) ?? 0;
1056
+ out += c < 32 && c !== 9 && c !== 10 || c >= 127 && c <= 159 ? `\\x${c.toString(16).padStart(2, "0")}` : ch;
1057
+ }
1058
+ return out;
1059
+ }
1060
+ const DEFAULT_RESOLVERS = { cloudflare: "https://cloudflare-dns.com/dns-query" };
1061
+ const DEFAULT_REACHABILITY = {
1062
+ ipv4: "https://ipv4.icanhazip.com",
1063
+ ipv6: "https://ipv6.icanhazip.com"
1064
+ };
1065
+ function defaultSleep(ms, signal) {
1066
+ return new Promise((resolve, reject) => {
1067
+ if (signal.aborted) {
1068
+ reject(signal.reason);
1069
+ return;
1070
+ }
1071
+ const t = setTimeout(() => {
1072
+ signal.removeEventListener("abort", stop);
1073
+ resolve();
1074
+ }, ms);
1075
+ const stop = () => {
1076
+ clearTimeout(t);
1077
+ reject(signal.reason);
1078
+ };
1079
+ signal.addEventListener("abort", stop, { once: true });
1080
+ });
1081
+ }
1082
+ const REACH_TIMEOUT = 5e3;
1083
+ function failure(err, ms, signal) {
1084
+ if (signal.aborted) return "(stopped)";
1085
+ if (err instanceof DOMException && err.name === "TimeoutError") return `(no answer in ${REACH_TIMEOUT / 1e3} s)`;
1086
+ return `(failed after ${Math.round(ms)} ms)`;
1087
+ }
1088
+ function rows(pairs) {
1089
+ const width = Math.max(...pairs.map(([k]) => k.length)) + 2;
1090
+ return pairs.map(([k, v]) => k.padEnd(width) + v).join("\n") + "\n";
1091
+ }
1092
+ const ipcalc = {
1093
+ name: "ipcalc",
1094
+ summary: "IPv4 and IPv6 address math",
1095
+ usage: "ipcalc <address>[/<prefix>] [--split <prefix>] [--contains <address>]",
1096
+ flags: {
1097
+ split: {
1098
+ long: "split",
1099
+ type: "number",
1100
+ description: "list the subnets of this prefix"
1101
+ },
1102
+ contains: {
1103
+ long: "contains",
1104
+ type: "string",
1105
+ description: "whether the network holds this address"
1106
+ }
1107
+ },
1108
+ manual: [
1109
+ "Network, mask, hosts, and the kind of range (private, global, ...) of an address",
1110
+ "and prefix. IPv4 is four decimal parts; IPv6 takes no zone id. --split lists up to",
1111
+ "256 subnets and otherwise counts them. No hostnames: dig resolves names."
1112
+ ].join("\n"),
1113
+ run: async (p) => {
1114
+ const arg = p.args[0];
1115
+ if (!arg || p.args.length > 1) {
1116
+ await p.err("usage: ipcalc <address>[/<prefix>] [--split <prefix>] [--contains <address>]\n");
1117
+ return 2;
1118
+ }
1119
+ const a = parseAddress(arg);
1120
+ if (typeof a === "string") {
1121
+ await p.err(`ipcalc: ${a}\n`);
1122
+ return 2;
1123
+ }
1124
+ const n = network(a);
1125
+ const contains = p.flags["contains"];
1126
+ if (typeof contains === "string") {
1127
+ const b = parseAddress(contains);
1128
+ if (typeof b === "string" || b.cidr) {
1129
+ await p.err(`ipcalc: ${typeof b === "string" ? b : "--contains takes an address, not a network"}\n`);
1130
+ return 2;
1131
+ }
1132
+ const inside = b.family === a.family && b.value >= n.network && b.value <= n.last;
1133
+ await p.out(`${format(b.family, b.value)} ${inside ? "is" : "is not"} in ${format(a.family, n.network)}/${a.prefix}\n`);
1134
+ return inside ? 0 : 1;
1135
+ }
1136
+ const split = p.flags["split"];
1137
+ if (typeof split === "number") {
1138
+ if (!Number.isInteger(split) || split < a.prefix || split > a.bits) {
1139
+ await p.err(`ipcalc: --split takes a prefix from /${a.prefix} to /${a.bits}\n`);
1140
+ return 2;
1141
+ }
1142
+ const count = 1n << BigInt(split - a.prefix);
1143
+ const step = 1n << BigInt(a.bits - split);
1144
+ if (count > 256n) {
1145
+ await p.out(`${count} subnets of /${split} in ${format(a.family, n.network)}/${a.prefix} (more than 256: not listed)\n`);
1146
+ return 0;
1147
+ }
1148
+ const lines = [];
1149
+ for (let i = 0n; i < count; i++) lines.push(`${format(a.family, n.network + i * step)}/${split}`);
1150
+ await p.out(lines.join("\n") + "\n");
1151
+ return 0;
1152
+ }
1153
+ const h = hosts(a);
1154
+ const pairs = [];
1155
+ if (a.cidr) pairs.push(["address", format(a.family, a.value)]);
1156
+ pairs.push(["network", `${format(a.family, n.network)}/${a.prefix}`]);
1157
+ if (a.family === "ipv4") {
1158
+ const m = mask(a);
1159
+ pairs.push(["netmask", format("ipv4", m)], ["wildcard", format("ipv4", m ^ 4294967295n)]);
1160
+ if (a.prefix < 31) pairs.push(["broadcast", format("ipv4", n.last)]);
1161
+ }
1162
+ const span = h.first === h.last ? format(a.family, h.first) : `${format(a.family, h.first)} - ${format(a.family, h.last)}`;
1163
+ pairs.push(["hosts", `${span} (${h.count.toLocaleString("en-US")})`], ["kind", a.range]);
1164
+ await p.out(rows(pairs));
1165
+ return 0;
1166
+ }
1167
+ };
1168
+ const TYPES = {
1169
+ A: 1,
1170
+ NS: 2,
1171
+ CNAME: 5,
1172
+ SOA: 6,
1173
+ MX: 15,
1174
+ TXT: 16,
1175
+ AAAA: 28,
1176
+ CAA: 257
1177
+ };
1178
+ const TYPE_NAMES = Object.fromEntries(Object.entries(TYPES).map(([k, v]) => [v, k]));
1179
+ const STATUS = {
1180
+ 0: "NOERROR",
1181
+ 1: "FORMERR",
1182
+ 2: "SERVFAIL",
1183
+ 3: "NXDOMAIN",
1184
+ 4: "NOTIMP",
1185
+ 5: "REFUSED"
1186
+ };
1187
+ const HOSTNAME = /^(?=.{1,253}\.?$)([a-z0-9_]([a-z0-9_-]{0,61}[a-z0-9_])?\.)*[a-z0-9_]([a-z0-9_-]{0,61}[a-z0-9_])?\.?$/i;
1188
+ function dig(o) {
1189
+ const names = Object.keys(o.resolvers);
1190
+ return {
1191
+ name: "dig",
1192
+ summary: "DNS lookups over HTTPS",
1193
+ usage: `dig [@${names.join("|@")}] <name> [${Object.keys(TYPES).join("|")}]`,
1194
+ flags: {},
1195
+ manual: ["Asks a DNS-over-HTTPS resolver (the site's: " + names.join(", ") + ") and prints the", "answer section. It runs in your browser; the resolver sees the name you ask for."].join("\n"),
1196
+ run: async (p) => {
1197
+ let resolver = names[0] ?? "";
1198
+ const words = [];
1199
+ for (const a of p.args) if (a.startsWith("@")) resolver = a.slice(1);
1200
+ else words.push(a);
1201
+ const [name, typeWord = "A", extra] = words;
1202
+ const url = Object.hasOwn(o.resolvers, resolver) ? o.resolvers[resolver] : void 0;
1203
+ if (!url) {
1204
+ await p.err(`dig: no resolver ${resolver}; this site has ${names.join(", ")}\n`);
1205
+ return 2;
1206
+ }
1207
+ const type = typeWord.toUpperCase();
1208
+ if (!name || extra !== void 0 || !HOSTNAME.test(name) || !(type in TYPES)) {
1209
+ await p.err(`usage: dig [@resolver] <name> [${Object.keys(TYPES).join("|")}]\n`);
1210
+ return 2;
1211
+ }
1212
+ let body;
1213
+ try {
1214
+ const query = new URL(url);
1215
+ query.searchParams.set("name", name);
1216
+ query.searchParams.set("type", type);
1217
+ const res = await o.fetch(query.toString(), {
1218
+ headers: { accept: "application/dns-json" },
1219
+ redirect: "error",
1220
+ signal: p.signal
1221
+ });
1222
+ if (!res.ok) throw new Error(`HTTP ${res.status}`);
1223
+ body = await res.json();
1224
+ } catch (err) {
1225
+ await p.err(`dig: ${resolver}: ${err instanceof Error ? err.message : String(err)}\n`);
1226
+ return 1;
1227
+ }
1228
+ const lines = [`;; ${STATUS[body.Status] ?? `status ${body.Status}`} from ${resolver}`];
1229
+ for (const a of body.Answer ?? []) lines.push([
1230
+ printable(a.name),
1231
+ String(a.TTL),
1232
+ "IN",
1233
+ TYPE_NAMES[a.type] ?? String(a.type),
1234
+ printable(a.data)
1235
+ ].join(" "));
1236
+ await p.out(lines.join("\n") + "\n");
1237
+ return body.Status === 0 ? 0 : 1;
1238
+ }
1239
+ };
1240
+ }
1241
+ function ipv6(o) {
1242
+ return {
1243
+ name: "ipv6",
1244
+ summary: "whether your network reaches the internet over IPv4 and IPv6",
1245
+ usage: "ipv6",
1246
+ flags: {},
1247
+ manual: [
1248
+ "Fetches an IPv4-only and an IPv6-only endpoint from your browser and shows which",
1249
+ "answered, the address each saw, and how long it took. Those endpoints see your",
1250
+ "addresses. It tests your network, not this site's."
1251
+ ].join("\n"),
1252
+ run: async (p) => {
1253
+ if (p.args.length > 0) {
1254
+ await p.err("usage: ipv6\n");
1255
+ return 2;
1256
+ }
1257
+ const probe = async (url) => {
1258
+ const start = o.now();
1259
+ try {
1260
+ const res = await o.fetch(url, {
1261
+ cache: "no-store",
1262
+ redirect: "error",
1263
+ signal: AbortSignal.any([p.signal, AbortSignal.timeout(REACH_TIMEOUT)])
1264
+ });
1265
+ const body = (await res.text()).trim();
1266
+ const seen = parseAddress(body);
1267
+ return {
1268
+ ok: res.ok,
1269
+ text: typeof seen === "string" ? "(an unexpected answer)" : body,
1270
+ ms: o.now() - start
1271
+ };
1272
+ } catch (err) {
1273
+ const ms = o.now() - start;
1274
+ return {
1275
+ ok: false,
1276
+ text: failure(err, ms, p.signal),
1277
+ ms
1278
+ };
1279
+ }
1280
+ };
1281
+ const [v4, v6] = await Promise.all([probe(o.reachability.ipv4), probe(o.reachability.ipv6)]);
1282
+ const line = (label, r) => `${label} ${r.ok ? "reachable " : "unreachable"} ${printable(r.text)}${r.ok ? ` ${Math.round(r.ms)} ms` : ""}`;
1283
+ const verdict = v4.ok && v6.ok ? "dual stack" : v4.ok ? "IPv4 only" : v6.ok ? "IPv6 only" : "no connectivity";
1284
+ await p.out([
1285
+ line("ipv4", v4),
1286
+ line("ipv6", v6),
1287
+ `your network: ${verdict}`
1288
+ ].join("\n") + "\n");
1289
+ return v4.ok || v6.ok ? 0 : 1;
1290
+ }
1291
+ };
1292
+ }
1293
+ const MAX_COUNT = 10;
1294
+ function httping(o) {
1295
+ const names = Object.keys(o.endpoints);
1296
+ return {
1297
+ name: "httping",
1298
+ summary: "HTTPS round-trip times to this site's endpoints",
1299
+ usage: `httping <${names.join("|")}> [-c count]`,
1300
+ flags: { count: {
1301
+ long: "count",
1302
+ short: "c",
1303
+ type: "number",
1304
+ default: 4,
1305
+ description: `requests, at most ${MAX_COUNT}`
1306
+ } },
1307
+ manual: [
1308
+ "Times small HTTPS requests, one a second, from your browser to an endpoint this",
1309
+ "site names. Each time covers the request and response (the first also the",
1310
+ "connection and TLS). It is not ICMP ping."
1311
+ ].join("\n"),
1312
+ run: async (p) => {
1313
+ const name = p.args[0] ?? "";
1314
+ const url = Object.hasOwn(o.endpoints, name) ? o.endpoints[name] : void 0;
1315
+ const count = Number(p.flags["count"]);
1316
+ if (!url || p.args.length !== 1) {
1317
+ await p.err(`usage: httping <${names.join("|")}> [-c count]\n`);
1318
+ return 2;
1319
+ }
1320
+ if (!Number.isInteger(count) || count < 1 || count > MAX_COUNT) {
1321
+ await p.err(`httping: -c takes 1 to ${MAX_COUNT}\n`);
1322
+ return 2;
1323
+ }
1324
+ await p.out(`HTTPS ${name}: ${count} requests (request and response time, not ICMP)\n`);
1325
+ const times = [];
1326
+ for (let i = 1; i <= count; i++) {
1327
+ const start = o.now();
1328
+ try {
1329
+ const res = await o.fetch(url, {
1330
+ cache: "no-store",
1331
+ redirect: "error",
1332
+ signal: AbortSignal.any([p.signal, AbortSignal.timeout(REACH_TIMEOUT)])
1333
+ });
1334
+ await res.arrayBuffer();
1335
+ const ms = o.now() - start;
1336
+ times.push(ms);
1337
+ await p.out(`seq=${i} status=${res.status} time=${ms.toFixed(1)} ms\n`);
1338
+ } catch (err) {
1339
+ if (p.signal.aborted) break;
1340
+ await p.out(`seq=${i} ${failure(err, o.now() - start, p.signal).slice(1, -1)}\n`);
1341
+ }
1342
+ if (i < count) try {
1343
+ await o.sleep(1e3, p.signal);
1344
+ } catch {
1345
+ break;
1346
+ }
1347
+ }
1348
+ if (times.length > 0) {
1349
+ const avg = times.reduce((a, b) => a + b, 0) / times.length;
1350
+ await p.out(`${times.length}/${count} answered, min/avg/max ${Math.min(...times).toFixed(1)}/${avg.toFixed(1)}/${Math.max(...times).toFixed(1)} ms\n`);
1351
+ } else await p.out(`0/${count} answered\n`);
1352
+ return times.length > 0 ? 0 : 1;
1353
+ }
1354
+ };
1355
+ }
1356
+ /** The network commands, for createRite's `commands`. */
1357
+ function commands(options = {}) {
1358
+ const f = options.fetch ?? ((...a) => fetch(...a));
1359
+ const now = options.now ?? (() => performance.now());
1360
+ const out = [ipcalc, dig({
1361
+ resolvers: options.resolvers ?? DEFAULT_RESOLVERS,
1362
+ fetch: f
1363
+ })];
1364
+ const reach = options.reachability ?? DEFAULT_REACHABILITY;
1365
+ if (reach !== false) out.push(ipv6({
1366
+ reachability: reach,
1367
+ fetch: f,
1368
+ now
1369
+ }));
1370
+ if (options.endpoints && Object.keys(options.endpoints).length > 0) out.push(httping({
1371
+ endpoints: options.endpoints,
1372
+ fetch: f,
1373
+ now,
1374
+ sleep: options.sleep ?? defaultSleep
1375
+ }));
1376
+ return out;
1377
+ }
1378
+ export { DEFAULT_REACHABILITY, DEFAULT_RESOLVERS, commands, ipcalc, printable };
1379
+
1380
+ //# sourceMappingURL=net.js.map