systeminformation 6.0.0-beta.0 → 6.0.0-beta.10
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/README.md +37 -7
- package/dist/bsd/network-stats.js +2 -2
- package/dist/bsd/os-info.d.ts +3 -0
- package/dist/bsd/os-info.js +9 -0
- package/dist/common/acceleration.d.ts +8 -0
- package/dist/common/acceleration.js +86 -0
- package/dist/common/defaults.d.ts +2 -1
- package/dist/common/defaults.js +23 -6
- package/dist/common/exec.js +1 -1
- package/dist/common/files.d.ts +9 -0
- package/dist/common/files.js +67 -3
- package/dist/common/filesys.d.ts +10 -0
- package/dist/common/filesys.js +41 -10
- package/dist/common/internet.d.ts +5 -0
- package/dist/common/internet.js +46 -1
- package/dist/common/mappings.d.ts +1 -1
- package/dist/common/mappings.js +1134 -1134
- package/dist/common/network.js +4 -4
- package/dist/common/nvidia.d.ts +1 -1
- package/dist/common/nvidia.js +4 -5
- package/dist/common/parse.d.ts +4 -6
- package/dist/common/parse.js +24 -69
- package/dist/common/security.d.ts +1 -0
- package/dist/common/security.js +3 -1
- package/dist/common/types.d.ts +79 -23
- package/dist/cpu-current-load.js +28 -6
- package/dist/cpu-current-speed.js +5 -3
- package/dist/darwin/disk-layout.js +10 -6
- package/dist/darwin/disks-io.js +3 -3
- package/dist/darwin/displays.js +3 -1
- package/dist/darwin/fans.d.ts +2 -0
- package/dist/darwin/fans.js +28 -0
- package/dist/darwin/index.d.ts +2 -0
- package/dist/darwin/index.js +6 -2
- package/dist/darwin/network-interfaces.js +5 -10
- package/dist/darwin/network-stats.js +5 -5
- package/dist/darwin/os-info.d.ts +1 -0
- package/dist/darwin/os-info.js +32 -2
- package/dist/darwin/serial-ports.d.ts +2 -0
- package/dist/darwin/serial-ports.js +94 -0
- package/dist/fans.d.ts +1 -0
- package/dist/fans.js +17 -0
- package/dist/get-data.d.ts +6 -2
- package/dist/get-data.js +6 -2
- package/dist/index.d.ts +3 -0
- package/dist/index.js +8 -2
- package/dist/inet-public-ip.d.ts +2 -0
- package/dist/inet-public-ip.js +10 -0
- package/dist/linux/audio.js +59 -0
- package/dist/linux/baseboard.js +9 -20
- package/dist/linux/bios.js +6 -15
- package/dist/linux/camera.js +2 -1
- package/dist/linux/chassis.js +4 -10
- package/dist/linux/cpu-temperature.js +34 -19
- package/dist/linux/cpu.js +3 -1
- package/dist/linux/disk-layout.js +7 -10
- package/dist/linux/disks-io.js +9 -9
- package/dist/linux/displays.js +6 -1
- package/dist/linux/fans.d.ts +2 -0
- package/dist/linux/fans.js +92 -0
- package/dist/linux/fs-size.js +160 -34
- package/dist/linux/fs-stats.js +6 -9
- package/dist/linux/gpu.d.ts +13 -0
- package/dist/linux/gpu.js +111 -1
- package/dist/linux/index.d.ts +2 -0
- package/dist/linux/index.js +6 -2
- package/dist/linux/mem-layout.js +2 -2
- package/dist/linux/network-interfaces.js +36 -39
- package/dist/linux/network-stats.js +8 -36
- package/dist/linux/npu.js +2 -1
- package/dist/linux/os-info.js +35 -10
- package/dist/linux/printer.js +4 -4
- package/dist/linux/process-load.js +9 -12
- package/dist/linux/processes.js +89 -80
- package/dist/linux/serial-ports.d.ts +2 -0
- package/dist/linux/serial-ports.js +102 -0
- package/dist/linux/services.js +179 -47
- package/dist/linux/system.js +1 -7
- package/dist/linux/time.d.ts +2 -2
- package/dist/linux/time.js +3 -3
- package/dist/linux/uuid.js +4 -10
- package/dist/serial-ports.d.ts +1 -0
- package/dist/serial-ports.js +17 -0
- package/dist/time.d.ts +1 -1
- package/dist/versions.js +60 -77
- package/dist/windows/block-devices.d.ts +1 -0
- package/dist/windows/block-devices.js +15 -5
- package/dist/windows/disk-layout.js +21 -1
- package/dist/windows/disks-io.js +8 -5
- package/dist/windows/displays.js +29 -12
- package/dist/windows/fans.d.ts +2 -0
- package/dist/windows/fans.js +71 -0
- package/dist/windows/index.d.ts +2 -0
- package/dist/windows/index.js +6 -2
- package/dist/windows/network-interfaces.js +20 -29
- package/dist/windows/network-stats.js +4 -2
- package/dist/windows/os-info.js +5 -0
- package/dist/windows/process-load.js +7 -5
- package/dist/windows/processes.js +17 -11
- package/dist/windows/serial-ports.d.ts +3 -0
- package/dist/windows/serial-ports.js +73 -0
- package/dist/windows/services.js +3 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -49,6 +49,8 @@ in a browser.
|
|
|
49
49
|
- `npu()` - detected NPUs / AI accelerators (experimental)
|
|
50
50
|
- `software()` - installed software / applications
|
|
51
51
|
- `npm()` - globally installed npm packages
|
|
52
|
+
- `fans()` - detected fans with rpm and pwm
|
|
53
|
+
- `serialPorts()` - detected serial / COM ports
|
|
52
54
|
|
|
53
55
|
### Extended Windows support
|
|
54
56
|
|
|
@@ -163,7 +165,7 @@ implementations can be tree-shaken away.
|
|
|
163
165
|
|
|
164
166
|
- complete rewrite in TypeScript with typed declarations for every function
|
|
165
167
|
- modular imports: load the whole library, a single operating system, or a single function
|
|
166
|
-
- new functions: `camera()`, `keyboard()`, `mouse()`, `thunderbolt()`, `pci()`, `npu()`, `software()`, `npm()`
|
|
168
|
+
- new functions: `camera()`, `keyboard()`, `mouse()`, `thunderbolt()`, `pci()`, `npu()`, `software()`, `npm()`, `fans()`, `serialPorts()`
|
|
167
169
|
- extended Windows support: `disksIO()`, `fsStats()`, `fsOpenFiles()`, `thunderbolt()`
|
|
168
170
|
- `time()` and `version()` are now asynchronous - all functions are async (async/await preferred, promises as alternative)
|
|
169
171
|
- callbacks are no longer supported
|
|
@@ -289,6 +291,12 @@ Full function reference with examples can be found at [https://systeminformation
|
|
|
289
291
|
| | max | X | X | X | X | | max temperature |
|
|
290
292
|
| | socket | X | | | | | array socket temperatures |
|
|
291
293
|
| | chipset | X | | | | | chipset temperature |
|
|
294
|
+
| si.fans() | [{...}] | X | | X* | X* | | detected fans |
|
|
295
|
+
| | [0].id | X | | X* | X* | | identifier, e.g. hwmon2/fan1 |
|
|
296
|
+
| | [0].label | X | | X* | X* | | label if the driver provides one |
|
|
297
|
+
| | [0].rpm | X | | X* | X* | | speed in rpm (or null) |
|
|
298
|
+
| | [0].pwm | X | | X* | X* | | duty cycle in % (or null) |
|
|
299
|
+
| | [0].source | X | | X* | X* | | chip / provider the value came from |
|
|
292
300
|
| si.npu() | [{...}] | X | | X | X | | detected NPUs / AI accelerators |
|
|
293
301
|
| | [0].vendor | X | | X | X | | vendor (Intel, AMD, Apple, ...) |
|
|
294
302
|
| | [0].name | X | | X | X | | name |
|
|
@@ -380,6 +388,7 @@ On Windows, `si.displays()` reports physical monitors: in duplicate/mirror mode
|
|
|
380
388
|
| | [0].serial | | | X | X | | serial number |
|
|
381
389
|
| | [0].displayId | | | X | X | | display ID |
|
|
382
390
|
| | [0].main | X | | X | X | | true if main monitor |
|
|
391
|
+
| | [0].mirror | X | | X | X | | true if mirrored / duplicated |
|
|
383
392
|
| | [0].builtin | X | | X | | | true if built-in monitor |
|
|
384
393
|
| | [0].connection | X | | X | X | | e.g. DisplayPort or HDMI |
|
|
385
394
|
| | [0].sizeX | X | | | X | | size in mm horizontal |
|
|
@@ -392,6 +401,7 @@ On Windows, `si.displays()` reports physical monitors: in duplicate/mirror mode
|
|
|
392
401
|
| | [0].positionX | X | | X | X | | display position X |
|
|
393
402
|
| | [0].positionY | X | | X | X | | display position Y |
|
|
394
403
|
| | [0].currentRefreshRate | X | | X | X | | current screen refresh rate |
|
|
404
|
+
| | [0].scale | | | | X | | DPI scaling factor, e.g. 1.5 |
|
|
395
405
|
|
|
396
406
|
#### 7. Operating System
|
|
397
407
|
|
|
@@ -453,6 +463,7 @@ On Windows, `si.displays()` reports physical monitors: in duplicate/mirror mode
|
|
|
453
463
|
| | currentLoadSystem | X | | X | X | X | CPU load system in % |
|
|
454
464
|
| | currentLoadNice | X | | X | X | X | CPU load nice in % |
|
|
455
465
|
| | currentLoadIdle | X | | X | X | X | CPU load idle in % |
|
|
466
|
+
| | currentLoadIowait | X | | | | | CPU load waiting for IO in % (Linux only, 0 elsewhere) |
|
|
456
467
|
| | currentLoadIrq | X | | X | X | X | CPU load system in % |
|
|
457
468
|
| | rawCurrentLoad... | X | | X | X | X | CPU load raw values (ticks) |
|
|
458
469
|
| | cpus[] | X | | X | X | X | current loads per CPU in % + raw ticks |
|
|
@@ -470,6 +481,7 @@ On Windows, `si.displays()` reports physical monitors: in duplicate/mirror mode
|
|
|
470
481
|
| | ...[0].cpu | X | X | X | X | X | process % CPU usage |
|
|
471
482
|
| | ...[0].cpuu | X | X | | X | | process % CPU usage (user) |
|
|
472
483
|
| | ...[0].cpus | X | X | | X | | process % CPU usage (system) |
|
|
484
|
+
| | ...[0].cpuTime | X | X | X | X | X | process cpu time in seconds (own, without reaped children); null if not available |
|
|
473
485
|
| | ...[0].mem | X | X | X | X | X | process memory % |
|
|
474
486
|
| | ...[0].priority | X | X | X | X | X | process priority |
|
|
475
487
|
| | ...[0].memVsz | X | X | X | X | X | process virtual memory size |
|
|
@@ -542,12 +554,12 @@ On Windows, `si.displays()` reports physical monitors: in duplicate/mirror mode
|
|
|
542
554
|
| | rIO | X | | X | X | | read IOs on all mounted drives |
|
|
543
555
|
| | wIO | X | | X | X | | write IOs on all mounted drives |
|
|
544
556
|
| | tIO | X | | X | X | | write IOs on all mounted drives |
|
|
545
|
-
| | rIO_sec | X | | X | X | | read IO per sec (* see notes)
|
|
546
|
-
| | wIO_sec | X | | X | X | | write IO per sec (* see notes)
|
|
547
|
-
| | tIO_sec | X | | X | X | | total IO per sec (* see notes)
|
|
548
|
-
| | rWaitTime | X | | | | | read IO request time (*
|
|
549
|
-
| | wWaitTime | X | | | | | write IO request time (*
|
|
550
|
-
| | tWaitTime | X | | | | | total IO request time (*
|
|
557
|
+
| | rIO_sec | X | | X | X | | read IO operations per sec, not bytes (* see notes) |
|
|
558
|
+
| | wIO_sec | X | | X | X | | write IO operations per sec, not bytes (* see notes) |
|
|
559
|
+
| | tIO_sec | X | | X | X | | total IO operations per sec, not bytes (* see notes) |
|
|
560
|
+
| | rWaitTime | X | | | | | read IO request time in ms during interval, null on 1st call (* notes) |
|
|
561
|
+
| | wWaitTime | X | | | | | write IO request time in ms during interval, null on 1st call (* notes) |
|
|
562
|
+
| | tWaitTime | X | | | | | total IO request time in ms during interval, null on 1st call (* notes) |
|
|
551
563
|
| | rWaitPercent | X | | | | | read IO request time percent (* see notes) |
|
|
552
564
|
| | wWaitPercent | X | | | | | write IO request time percent (* see notes) |
|
|
553
565
|
| | tWaitPercent | X | | | | | total IO request time percent (* see notes) |
|
|
@@ -608,6 +620,15 @@ On Windows, `si.displays()` reports physical monitors: in duplicate/mirror mode
|
|
|
608
620
|
| | [0].maxPower | X | | | | | max power |
|
|
609
621
|
| | [0].default | X | | X | X | | is default printer |
|
|
610
622
|
| | [0].serialNumber | | | X | | | serial number |
|
|
623
|
+
| si.serialPorts() | [{...}] | X | | X | X | | detected serial / COM ports |
|
|
624
|
+
| | [0].device | X | | X | X | | device path (COMx on Windows) |
|
|
625
|
+
| | [0].name | X | | X | X | | product / friendly name |
|
|
626
|
+
| | [0].manufacturer | X | | X | X | | manufacturer |
|
|
627
|
+
| | [0].serialNumber | X | | X | X | | serial number (USB only) |
|
|
628
|
+
| | [0].vendorId | X | | X | X | | vendor id (hex) |
|
|
629
|
+
| | [0].productId | X | | X | X | | product id (hex) |
|
|
630
|
+
| | [0].pnpId | X | | | X | | stable id (by-id / DeviceID) |
|
|
631
|
+
| | [0].type | X | | X | X | | usb, onboard, pci, bluetooth |
|
|
611
632
|
|
|
612
633
|
#### 11. Devices
|
|
613
634
|
|
|
@@ -1003,6 +1024,15 @@ $ npm install macos-temperature-sensor --save
|
|
|
1003
1024
|
|
|
1004
1025
|
`systeminformation` will then detect this additional library and return the temperature when calling systeminformations standard function `cpuTemperature()`.
|
|
1005
1026
|
On Apple Silicon machines `macos-temperature-sensor` also enables the GPU temperature (`temperatureGpu`) in `gpu()`
|
|
1027
|
+
and - as soon as the package exposes them - the fan speeds in `fans()`.
|
|
1028
|
+
|
|
1029
|
+
#### Windows - Fan Speed
|
|
1030
|
+
|
|
1031
|
+
Windows itself does not expose actual fan speeds: `Win32_Fan` only reports that a fan exists, its `DesiredSpeed` is the *requested* speed and is left empty by virtually every mainboard. Real values are read from a running [LibreHardwareMonitor](https://github.com/LibreHardwareMonitor/LibreHardwareMonitor) or OpenHardwareMonitor, which publish their sensors in an own WMI namespace. Without one of these tools running, `fans()` returns an empty array or entries without `rpm`.
|
|
1032
|
+
|
|
1033
|
+
#### Serial Ports
|
|
1034
|
+
|
|
1035
|
+
`serialPorts()` only *enumerates* ports - opening one (baud rate, termios, RTS toggling) needs a native binding and is out of scope for this zero-dependency library. Two things worth knowing: on Linux a port shows up in the list even when your user is not in the `dialout` / `uucp` group, so listing can succeed while opening fails; on Windows the `COMx` number is reassigned per USB port, so `pnpId` is the only stable key. RS-232 and RS-485 cannot be told apart by enumeration - an RS-485 transceiver looks like an ordinary UART to the operating system - so no such information is reported.
|
|
1006
1036
|
|
|
1007
1037
|
#### Windows Temperature, Battery, ...
|
|
1008
1038
|
|
|
@@ -9,7 +9,7 @@ const darwin_1 = require("../darwin");
|
|
|
9
9
|
const network_1 = require("../common/network");
|
|
10
10
|
const _network = {};
|
|
11
11
|
const networkStatsSingle = async (iface) => {
|
|
12
|
-
const defaults = defaults_1.initNetworkSpeed;
|
|
12
|
+
const defaults = { ...defaults_1.initNetworkSpeed, iface };
|
|
13
13
|
if (!_network[iface] || (_network[iface] && !_network[iface].ms) || (_network[iface] && _network[iface].ms && Date.now() - _network[iface].ms >= 500)) {
|
|
14
14
|
let operstate = 'unknown';
|
|
15
15
|
let rx_bytes = 0;
|
|
@@ -18,7 +18,7 @@ const networkStatsSingle = async (iface) => {
|
|
|
18
18
|
let rx_errors = 0;
|
|
19
19
|
let tx_dropped = 0;
|
|
20
20
|
let tx_errors = 0;
|
|
21
|
-
const
|
|
21
|
+
const stdout = await (0, exec_1.execSecure)('netstat', ['-ibndI', iface]);
|
|
22
22
|
if (stdout) {
|
|
23
23
|
const lines = stdout.split('\n');
|
|
24
24
|
for (let i = 1; i < lines.length; i++) {
|
package/dist/bsd/os-info.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export declare const osInfo: () => Promise<import("../common/types").OsData | {
|
|
|
6
6
|
codename: string;
|
|
7
7
|
codepage: string;
|
|
8
8
|
uefi: true | null;
|
|
9
|
+
lastUpdate: Date | null;
|
|
9
10
|
displayServer: string;
|
|
10
11
|
platform: string;
|
|
11
12
|
kernel: string;
|
|
@@ -15,6 +16,8 @@ export declare const osInfo: () => Promise<import("../common/types").OsData | {
|
|
|
15
16
|
build: string;
|
|
16
17
|
servicepack: string;
|
|
17
18
|
installDate: Date | null;
|
|
19
|
+
awake: boolean;
|
|
20
|
+
hwAcceleration: string[];
|
|
18
21
|
hypervizor?: boolean;
|
|
19
22
|
remoteSession?: boolean;
|
|
20
23
|
hypervisor?: boolean;
|
package/dist/bsd/os-info.js
CHANGED
|
@@ -6,6 +6,14 @@ const defaults_1 = require("../common/defaults");
|
|
|
6
6
|
const mappings_1 = require("../common/mappings");
|
|
7
7
|
const common_1 = require("../common");
|
|
8
8
|
const codepage_1 = require("../common/codepage");
|
|
9
|
+
const getLastUpdate = async () => {
|
|
10
|
+
const { stdout } = await (0, exec_1.execSave)('stat -f %m /var/db/pkg/local.sqlite /var/db/pkg /var/db/freebsd-update 2>/dev/null');
|
|
11
|
+
const times = (stdout || '')
|
|
12
|
+
.split('\n')
|
|
13
|
+
.map((line) => parseInt(line.trim(), 10))
|
|
14
|
+
.filter((sec) => sec > 0);
|
|
15
|
+
return times.length ? new Date(Math.max(...times) * 1000) : null;
|
|
16
|
+
};
|
|
9
17
|
const getDisplayServer = () => {
|
|
10
18
|
const sessionType = (process.env.XDG_SESSION_TYPE || '').toLowerCase();
|
|
11
19
|
return sessionType || (process.env.WAYLAND_DISPLAY ? 'wayland' : process.env.DISPLAY ? 'x11' : '');
|
|
@@ -31,6 +39,7 @@ const osInfo = async () => {
|
|
|
31
39
|
codename: '',
|
|
32
40
|
codepage: (0, codepage_1.getCodepage)(),
|
|
33
41
|
uefi: uefi || null,
|
|
42
|
+
lastUpdate: await getLastUpdate(),
|
|
34
43
|
displayServer: getDisplayServer()
|
|
35
44
|
};
|
|
36
45
|
return defaults;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hwAcceleration = exports.detectLayers = void 0;
|
|
4
|
+
const const_1 = require("./const");
|
|
5
|
+
const files_1 = require("./files");
|
|
6
|
+
const join = (paths, files, separator) => {
|
|
7
|
+
const result = [];
|
|
8
|
+
paths.forEach((path) => {
|
|
9
|
+
files.forEach((file) => {
|
|
10
|
+
result.push(`${path}${separator}${file}`);
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
return result;
|
|
14
|
+
};
|
|
15
|
+
const anyExists = async (files) => (await Promise.all(files.map((file) => (0, files_1.fileExists)(file)))).includes(true);
|
|
16
|
+
const detectLayers = async (candidates) => {
|
|
17
|
+
const detected = await Promise.all(candidates.map(async (candidate) => {
|
|
18
|
+
if (candidate.all) {
|
|
19
|
+
const groups = await Promise.all(candidate.all.map((group) => anyExists(group)));
|
|
20
|
+
return !groups.includes(false) ? candidate.name : '';
|
|
21
|
+
}
|
|
22
|
+
return candidate.any && (await anyExists(candidate.any)) ? candidate.name : '';
|
|
23
|
+
}));
|
|
24
|
+
return detected.filter(Boolean);
|
|
25
|
+
};
|
|
26
|
+
exports.detectLayers = detectLayers;
|
|
27
|
+
const envPaths = (value, separator = ':') => (value || '').split(separator).filter(Boolean);
|
|
28
|
+
const linuxCandidates = () => {
|
|
29
|
+
const paths = [
|
|
30
|
+
...envPaths(process.env.LD_LIBRARY_PATH),
|
|
31
|
+
'/usr/lib',
|
|
32
|
+
'/usr/lib64',
|
|
33
|
+
'/lib',
|
|
34
|
+
'/usr/lib/x86_64-linux-gnu',
|
|
35
|
+
'/usr/lib/aarch64-linux-gnu',
|
|
36
|
+
'/usr/local/lib',
|
|
37
|
+
'/usr/local/cuda/lib64',
|
|
38
|
+
'/opt/rocm/lib',
|
|
39
|
+
'/opt/intel/oneapi/lib'
|
|
40
|
+
];
|
|
41
|
+
const lib = (files) => join(paths, files, '/');
|
|
42
|
+
return [
|
|
43
|
+
{ name: 'cuda', all: [lib(['libnvidia-ml.so', 'libnvidia-ml.so.1']), lib(['libcudart.so', 'libcudart.so.11', 'libcudart.so.12', 'libcudart.so.13'])] },
|
|
44
|
+
{ name: 'rocm', any: lib(['libamdhip64.so', 'librocm_smi64.so']) },
|
|
45
|
+
{ name: 'oneapi', any: lib(['libze_loader.so', 'libze_loader.so.1']) },
|
|
46
|
+
{ name: 'vulkan', any: lib(['libvulkan.so', 'libvulkan.so.1']) },
|
|
47
|
+
{ name: 'opencl', any: lib(['libOpenCL.so', 'libOpenCL.so.1']) }
|
|
48
|
+
];
|
|
49
|
+
};
|
|
50
|
+
const windowsCandidates = () => {
|
|
51
|
+
const system = [`${const_1.WINDIR}\\System32`, `${const_1.WINDIR}\\SysWOW64`];
|
|
52
|
+
const cudaPath = process.env.CUDA_PATH ? [`${process.env.CUDA_PATH}\\bin`] : [];
|
|
53
|
+
const vendorPaths = envPaths(process.env.PATH, ';').filter((path) => /cuda|nvidia|vulkan|oneapi/i.test(path));
|
|
54
|
+
const paths = [...system, ...cudaPath, ...vendorPaths];
|
|
55
|
+
const lib = (files) => join(paths, files, '\\');
|
|
56
|
+
return [
|
|
57
|
+
{ name: 'cuda', all: [lib(['nvml.dll']), lib(['cudart64_11.dll', 'cudart64_12.dll', 'cudart64_13.dll'])] },
|
|
58
|
+
{ name: 'oneapi', any: lib(['ze_loader.dll']) },
|
|
59
|
+
{ name: 'vulkan', any: lib(['vulkan-1.dll']) },
|
|
60
|
+
{ name: 'opencl', any: lib(['OpenCL.dll']) },
|
|
61
|
+
{ name: 'dx12', any: join(system, ['d3d12.dll'], '\\') },
|
|
62
|
+
{ name: 'directml', any: join(system, ['DirectML.dll'], '\\') }
|
|
63
|
+
];
|
|
64
|
+
};
|
|
65
|
+
const darwinCandidates = () => {
|
|
66
|
+
const paths = ['/usr/lib', '/usr/local/lib', '/opt/homebrew/lib'];
|
|
67
|
+
const lib = (files) => join(paths, files, '/');
|
|
68
|
+
return [
|
|
69
|
+
{ name: 'metal', any: ['/System/Library/Frameworks/Metal.framework'] },
|
|
70
|
+
{ name: 'vulkan', any: lib(['libvulkan.dylib', 'libvulkan.1.dylib', 'libMoltenVK.dylib']) },
|
|
71
|
+
{ name: 'opencl', any: ['/System/Library/Frameworks/OpenCL.framework', ...lib(['libOpenCL.dylib'])] }
|
|
72
|
+
];
|
|
73
|
+
};
|
|
74
|
+
const hwAcceleration = async () => {
|
|
75
|
+
switch (true) {
|
|
76
|
+
case const_1.LINUX || const_1.FREEBSD || const_1.NETBSD || const_1.OPENBSD:
|
|
77
|
+
return (0, exports.detectLayers)(linuxCandidates());
|
|
78
|
+
case const_1.DARWIN:
|
|
79
|
+
return (0, exports.detectLayers)(darwinCandidates());
|
|
80
|
+
case const_1.WINDOWS:
|
|
81
|
+
return (0, exports.detectLayers)(windowsCandidates());
|
|
82
|
+
default:
|
|
83
|
+
return [];
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
exports.hwAcceleration = hwAcceleration;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { AudioData, BaseboardData, BatteryObject, BiosData, ChassisData, CpuCacheData, CpuObject, CpuTemperatureObject, DisksIoData, DisplayData, FsBlockDevicesData, FsOpenFilesData, FsStatsData, InetChecksiteData, MemData, NetworkInterfacesData, NetworkStatsData, NpuData, OsData, PciData, ProcessesData, SystemData, UsbData, UuidData } from './types';
|
|
1
|
+
import type { AudioData, BaseboardData, BatteryObject, BiosData, ChassisData, CpuCacheData, CpuObject, CpuTemperatureObject, DisksIoData, DisplayData, FsBlockDevicesData, FsOpenFilesData, FsStatsData, InetChecksiteData, MemData, NetworkInterfacesData, NetworkStatsData, NpuData, OsData, PciData, ProcessesData, SerialPortData, SystemData, UsbData, UuidData } from './types';
|
|
2
2
|
export declare const initBatteryResult: BatteryObject;
|
|
3
3
|
export declare const initAudioResult: AudioData;
|
|
4
|
+
export declare const initSerialPortResult: SerialPortData;
|
|
4
5
|
export declare const initUsbResult: UsbData;
|
|
5
6
|
export declare const initCpuResult: CpuObject;
|
|
6
7
|
export declare const initCpuCacheResult: CpuCacheData;
|
package/dist/common/defaults.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.initNetworkSpeed = exports.initPciData = exports.initNpuData = exports.initNetworkInterface = exports.initProcesses = exports.initDisplay = exports.initDiskIo = exports.initFsStats = exports.initFsBlockDevice = exports.initFsOpenFiles = exports.initSystem = exports.initBios = exports.initBaseboard = exports.initChassis = exports.initUUID = exports.initOsInfo = exports.initMemData = exports.initCheckSite = exports.initCpuTemperature = exports.initCpuCacheResult = exports.initCpuResult = exports.initUsbResult = exports.initAudioResult = exports.initBatteryResult = void 0;
|
|
3
|
+
exports.initNetworkSpeed = exports.initPciData = exports.initNpuData = exports.initNetworkInterface = exports.initProcesses = exports.initDisplay = exports.initDiskIo = exports.initFsStats = exports.initFsBlockDevice = exports.initFsOpenFiles = exports.initSystem = exports.initBios = exports.initBaseboard = exports.initChassis = exports.initUUID = exports.initOsInfo = exports.initMemData = exports.initCheckSite = exports.initCpuTemperature = exports.initCpuCacheResult = exports.initCpuResult = exports.initUsbResult = exports.initSerialPortResult = exports.initAudioResult = exports.initBatteryResult = void 0;
|
|
4
4
|
const node_os_1 = require("node:os");
|
|
5
|
+
const acceleration_1 = require("./acceleration");
|
|
5
6
|
const const_1 = require("./const");
|
|
6
7
|
const host_1 = require("./host");
|
|
7
8
|
exports.initBatteryResult = {
|
|
@@ -33,6 +34,16 @@ exports.initAudioResult = {
|
|
|
33
34
|
out: null,
|
|
34
35
|
status: ''
|
|
35
36
|
};
|
|
37
|
+
exports.initSerialPortResult = {
|
|
38
|
+
device: '',
|
|
39
|
+
name: null,
|
|
40
|
+
manufacturer: null,
|
|
41
|
+
serialNumber: null,
|
|
42
|
+
vendorId: null,
|
|
43
|
+
productId: null,
|
|
44
|
+
pnpId: null,
|
|
45
|
+
type: 'unknown'
|
|
46
|
+
};
|
|
36
47
|
exports.initUsbResult = {
|
|
37
48
|
id: null,
|
|
38
49
|
bus: null,
|
|
@@ -121,7 +132,10 @@ const initOsInfo = async () => {
|
|
|
121
132
|
servicepack: '',
|
|
122
133
|
uefi: false,
|
|
123
134
|
installDate: null,
|
|
124
|
-
|
|
135
|
+
lastUpdate: null,
|
|
136
|
+
displayServer: '',
|
|
137
|
+
awake: true,
|
|
138
|
+
hwAcceleration: await (0, acceleration_1.hwAcceleration)()
|
|
125
139
|
};
|
|
126
140
|
};
|
|
127
141
|
exports.initOsInfo = initOsInfo;
|
|
@@ -178,6 +192,7 @@ exports.initFsBlockDevice = {
|
|
|
178
192
|
size: 0,
|
|
179
193
|
physical: 'HDD',
|
|
180
194
|
uuid: '',
|
|
195
|
+
guid: '',
|
|
181
196
|
label: '',
|
|
182
197
|
model: '',
|
|
183
198
|
serial: '',
|
|
@@ -202,9 +217,9 @@ exports.initDiskIo = {
|
|
|
202
217
|
rIO_sec: null,
|
|
203
218
|
wIO_sec: null,
|
|
204
219
|
tIO_sec: null,
|
|
205
|
-
rWaitTime:
|
|
206
|
-
wWaitTime:
|
|
207
|
-
tWaitTime:
|
|
220
|
+
rWaitTime: null,
|
|
221
|
+
wWaitTime: null,
|
|
222
|
+
tWaitTime: null,
|
|
208
223
|
rWaitPercent: null,
|
|
209
224
|
wWaitPercent: null,
|
|
210
225
|
tWaitPercent: null,
|
|
@@ -219,6 +234,7 @@ exports.initDisplay = {
|
|
|
219
234
|
deviceName: '',
|
|
220
235
|
displayId: null,
|
|
221
236
|
main: false,
|
|
237
|
+
mirror: false,
|
|
222
238
|
builtin: false,
|
|
223
239
|
connection: '',
|
|
224
240
|
sizeX: null,
|
|
@@ -230,7 +246,8 @@ exports.initDisplay = {
|
|
|
230
246
|
currentResY: null,
|
|
231
247
|
positionX: 0,
|
|
232
248
|
positionY: 0,
|
|
233
|
-
currentRefreshRate: null
|
|
249
|
+
currentRefreshRate: null,
|
|
250
|
+
scale: null
|
|
234
251
|
};
|
|
235
252
|
exports.initProcesses = {
|
|
236
253
|
all: 0,
|
package/dist/common/exec.js
CHANGED
|
@@ -63,7 +63,7 @@ const execSave = async (cmd, options = {}) => {
|
|
|
63
63
|
return { stdout: stdout.toString(), stderr: stderr.toString() };
|
|
64
64
|
}
|
|
65
65
|
catch (e) {
|
|
66
|
-
return { stdout: e.stdout, stderr: e.stderr };
|
|
66
|
+
return { stdout: String(e.stdout ?? ''), stderr: String(e.stderr ?? '') };
|
|
67
67
|
}
|
|
68
68
|
};
|
|
69
69
|
exports.execSave = execSave;
|
package/dist/common/files.d.ts
CHANGED
|
@@ -1,2 +1,11 @@
|
|
|
1
1
|
export declare const getFilesInPath: (source: string) => Promise<string[]>;
|
|
2
2
|
export declare const fileExists: (file: string) => Promise<boolean>;
|
|
3
|
+
export declare const readSysfs: (file: string) => Promise<string>;
|
|
4
|
+
export declare const readFileLines: (file: string) => Promise<string[]>;
|
|
5
|
+
export declare const readSysfsMany: (dir: string, names: string[]) => Promise<string[]>;
|
|
6
|
+
export declare const readProcStats: (pids: any[]) => Promise<{
|
|
7
|
+
all: string;
|
|
8
|
+
procs: string[];
|
|
9
|
+
}>;
|
|
10
|
+
export declare const readFileMax: (file: string, maxBytes?: number) => Promise<string>;
|
|
11
|
+
export declare const DMI_PATH = "/sys/devices/virtual/dmi/id";
|
package/dist/common/files.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fileExists = exports.getFilesInPath = void 0;
|
|
3
|
+
exports.DMI_PATH = exports.readFileMax = exports.readProcStats = exports.readSysfsMany = exports.readFileLines = exports.readSysfs = exports.fileExists = exports.getFilesInPath = void 0;
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
5
|
const promises_1 = require("fs/promises");
|
|
6
6
|
const path_1 = require("path");
|
|
7
|
+
const security_1 = require("./security");
|
|
7
8
|
const getFilesInPath = async (source) => {
|
|
8
9
|
const fetchedFiles = [];
|
|
9
10
|
try {
|
|
10
|
-
const files = await (0, promises_1.readdir)(source);
|
|
11
|
+
const files = (await (0, promises_1.readdir)(source)).filter(security_1.isSafePathSegment);
|
|
11
12
|
for (const file of files) {
|
|
12
13
|
try {
|
|
13
14
|
const filepath = (0, path_1.join)(source, file);
|
|
@@ -17,7 +18,7 @@ const getFilesInPath = async (source) => {
|
|
|
17
18
|
}
|
|
18
19
|
if (stats.isDirectory()) {
|
|
19
20
|
const childFiles = await (0, promises_1.readdir)(filepath);
|
|
20
|
-
files.push(...childFiles.map((f) => (0, path_1.join)(file, f)));
|
|
21
|
+
files.push(...childFiles.filter(security_1.isSafePathSegment).map((f) => (0, path_1.join)(file, f)));
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
24
|
catch { }
|
|
@@ -37,3 +38,66 @@ const fileExists = async (file) => {
|
|
|
37
38
|
}
|
|
38
39
|
};
|
|
39
40
|
exports.fileExists = fileExists;
|
|
41
|
+
const readSysfs = async (file) => {
|
|
42
|
+
try {
|
|
43
|
+
return (await (0, promises_1.readFile)(file, 'utf8')).trim();
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return '';
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
exports.readSysfs = readSysfs;
|
|
50
|
+
const readFileLines = async (file) => {
|
|
51
|
+
try {
|
|
52
|
+
return (await (0, promises_1.readFile)(file, 'utf8')).split('\n');
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
exports.readFileLines = readFileLines;
|
|
59
|
+
const readSysfsMany = async (dir, names) => {
|
|
60
|
+
return Promise.all(names.map(async (name) => `${name}: ${await (0, exports.readSysfs)((0, path_1.join)(dir, name))}`));
|
|
61
|
+
};
|
|
62
|
+
exports.readSysfsMany = readSysfsMany;
|
|
63
|
+
const PROC_READ_BATCH = 64;
|
|
64
|
+
const readProcStats = async (pids) => {
|
|
65
|
+
const paths = [];
|
|
66
|
+
for (const pid of pids) {
|
|
67
|
+
const id = String(pid);
|
|
68
|
+
if (/^\d+$/.test(id)) {
|
|
69
|
+
paths.push(`/proc/${id}/stat`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const statLines = await (0, exports.readFileLines)('/proc/stat');
|
|
73
|
+
const procs = [];
|
|
74
|
+
for (let i = 0; i < paths.length; i += PROC_READ_BATCH) {
|
|
75
|
+
procs.push(...(await Promise.all(paths.slice(i, i + PROC_READ_BATCH).map((path) => (0, exports.readSysfs)(path)))));
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
all: statLines.find((line) => line.startsWith('cpu ')) || '',
|
|
79
|
+
procs: procs.filter((line) => line)
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
exports.readProcStats = readProcStats;
|
|
83
|
+
const readFileMax = async (file, maxBytes = 1024 * 1024) => {
|
|
84
|
+
let handle;
|
|
85
|
+
try {
|
|
86
|
+
handle = await (0, promises_1.open)(file, 'r');
|
|
87
|
+
const { size } = await handle.stat();
|
|
88
|
+
const buffer = Buffer.alloc(Math.min(size || maxBytes, maxBytes));
|
|
89
|
+
const { bytesRead } = await handle.read(buffer, 0, buffer.length, 0);
|
|
90
|
+
return buffer.toString('utf8', 0, bytesRead).trim();
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
return '';
|
|
94
|
+
}
|
|
95
|
+
finally {
|
|
96
|
+
try {
|
|
97
|
+
await handle?.close();
|
|
98
|
+
}
|
|
99
|
+
catch { }
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
exports.readFileMax = readFileMax;
|
|
103
|
+
exports.DMI_PATH = '/sys/devices/virtual/dmi/id';
|
package/dist/common/filesys.d.ts
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import type { FsBlockDevicesData } from './types';
|
|
2
|
+
export declare const zfsDatasets: () => Promise<{
|
|
3
|
+
byMount: Map<string, {
|
|
4
|
+
used: number;
|
|
5
|
+
available: number;
|
|
6
|
+
}>;
|
|
7
|
+
byName: Map<string, {
|
|
8
|
+
used: number;
|
|
9
|
+
available: number;
|
|
10
|
+
}>;
|
|
11
|
+
}>;
|
|
2
12
|
export declare const smartMonToolsInstalled: () => Promise<boolean>;
|
|
3
13
|
export declare const _fs_speed: any;
|
|
4
14
|
export declare const calcFsSpeed: (rx: number, wx: number) => any;
|
package/dist/common/filesys.js
CHANGED
|
@@ -1,11 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.matchDevicesWin = exports.matchDevicesLinux = exports.raidMatchLinux = exports.parseLinuxBlk = exports.blkStdoutToObject = exports.calcDiskIO = exports._disk_io = exports.calcFsSpeed = exports._fs_speed = exports.smartMonToolsInstalled = void 0;
|
|
3
|
+
exports.matchDevicesWin = exports.matchDevicesLinux = exports.raidMatchLinux = exports.parseLinuxBlk = exports.blkStdoutToObject = exports.calcDiskIO = exports._disk_io = exports.calcFsSpeed = exports._fs_speed = exports.smartMonToolsInstalled = exports.zfsDatasets = void 0;
|
|
4
4
|
const index_1 = require("./index");
|
|
5
5
|
const const_1 = require("./const");
|
|
6
6
|
const defaults_1 = require("./defaults");
|
|
7
7
|
const exec_1 = require("./exec");
|
|
8
8
|
let _smartMonToolsInstalled = null;
|
|
9
|
+
const zfsDatasets = async () => {
|
|
10
|
+
const byMount = new Map();
|
|
11
|
+
const byName = new Map();
|
|
12
|
+
let stdout = '';
|
|
13
|
+
try {
|
|
14
|
+
({ stdout } = await (0, exec_1.exec)('zfs list -H -p -o name,used,avail,mountpoint', { ...const_1.execOptsLinux, timeout: 5000 }));
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return { byMount, byName };
|
|
18
|
+
}
|
|
19
|
+
for (const line of stdout.toString().split('\n')) {
|
|
20
|
+
const parts = line.split('\t');
|
|
21
|
+
if (parts.length < 4) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const entry = { used: (0, index_1.toInt)(parts[1]), available: (0, index_1.toInt)(parts[2]) };
|
|
25
|
+
const mount = parts[3].trim();
|
|
26
|
+
byName.set(parts[0], entry);
|
|
27
|
+
if (mount.startsWith('/') && !byMount.has(mount)) {
|
|
28
|
+
byMount.set(mount, entry);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return { byMount, byName };
|
|
32
|
+
};
|
|
33
|
+
exports.zfsDatasets = zfsDatasets;
|
|
9
34
|
const smartMonToolsInstalled = async () => {
|
|
10
35
|
if (_smartMonToolsInstalled !== null) {
|
|
11
36
|
return _smartMonToolsInstalled;
|
|
@@ -84,12 +109,12 @@ const calcDiskIO = (rIO, wIO, rWaitTime, wWaitTime, tWaitTime) => {
|
|
|
84
109
|
result.rIO_sec = (result.rIO - exports._disk_io.rIO) / (result.ms / 1000);
|
|
85
110
|
result.wIO_sec = (result.wIO - exports._disk_io.wIO) / (result.ms / 1000);
|
|
86
111
|
result.tIO_sec = result.rIO_sec + result.wIO_sec;
|
|
87
|
-
result.rWaitTime = rWaitTime;
|
|
88
|
-
result.wWaitTime = wWaitTime;
|
|
89
|
-
result.tWaitTime = tWaitTime;
|
|
90
|
-
result.rWaitPercent = (
|
|
91
|
-
result.wWaitPercent = (
|
|
92
|
-
result.tWaitPercent = (
|
|
112
|
+
result.rWaitTime = rWaitTime - exports._disk_io.rWaitTime;
|
|
113
|
+
result.wWaitTime = wWaitTime - exports._disk_io.wWaitTime;
|
|
114
|
+
result.tWaitTime = tWaitTime - exports._disk_io.tWaitTime;
|
|
115
|
+
result.rWaitPercent = (result.rWaitTime * 100) / result.ms;
|
|
116
|
+
result.wWaitPercent = (result.wWaitTime * 100) / result.ms;
|
|
117
|
+
result.tWaitPercent = (result.tWaitTime * 100) / result.ms;
|
|
93
118
|
exports._disk_io.rIO = rIO;
|
|
94
119
|
exports._disk_io.wIO = wIO;
|
|
95
120
|
exports._disk_io.rIO_sec = result.rIO_sec;
|
|
@@ -98,6 +123,9 @@ const calcDiskIO = (rIO, wIO, rWaitTime, wWaitTime, tWaitTime) => {
|
|
|
98
123
|
exports._disk_io.rWaitTime = rWaitTime;
|
|
99
124
|
exports._disk_io.wWaitTime = wWaitTime;
|
|
100
125
|
exports._disk_io.tWaitTime = tWaitTime;
|
|
126
|
+
exports._disk_io.rWaitTimeDelta = result.rWaitTime;
|
|
127
|
+
exports._disk_io.wWaitTimeDelta = result.wWaitTime;
|
|
128
|
+
exports._disk_io.tWaitTimeDelta = result.tWaitTime;
|
|
101
129
|
exports._disk_io.rWaitPercent = result.rWaitPercent;
|
|
102
130
|
exports._disk_io.wWaitPercent = result.wWaitPercent;
|
|
103
131
|
exports._disk_io.tWaitPercent = result.tWaitPercent;
|
|
@@ -108,9 +136,9 @@ const calcDiskIO = (rIO, wIO, rWaitTime, wWaitTime, tWaitTime) => {
|
|
|
108
136
|
result.rIO = rIO;
|
|
109
137
|
result.wIO = wIO;
|
|
110
138
|
result.tIO = rIO + wIO;
|
|
111
|
-
result.rWaitTime =
|
|
112
|
-
result.wWaitTime =
|
|
113
|
-
result.tWaitTime =
|
|
139
|
+
result.rWaitTime = null;
|
|
140
|
+
result.wWaitTime = null;
|
|
141
|
+
result.tWaitTime = null;
|
|
114
142
|
exports._disk_io.rIO = rIO;
|
|
115
143
|
exports._disk_io.wIO = wIO;
|
|
116
144
|
exports._disk_io.rIO_sec = null;
|
|
@@ -119,6 +147,9 @@ const calcDiskIO = (rIO, wIO, rWaitTime, wWaitTime, tWaitTime) => {
|
|
|
119
147
|
exports._disk_io.rWaitTime = rWaitTime;
|
|
120
148
|
exports._disk_io.wWaitTime = wWaitTime;
|
|
121
149
|
exports._disk_io.tWaitTime = tWaitTime;
|
|
150
|
+
exports._disk_io.rWaitTimeDelta = null;
|
|
151
|
+
exports._disk_io.wWaitTimeDelta = null;
|
|
152
|
+
exports._disk_io.tWaitTimeDelta = null;
|
|
122
153
|
exports._disk_io.rWaitPercent = null;
|
|
123
154
|
exports._disk_io.wWaitPercent = null;
|
|
124
155
|
exports._disk_io.tWaitPercent = null;
|
package/dist/common/internet.js
CHANGED
|
@@ -3,9 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.checkWebsite = void 0;
|
|
6
|
+
exports.publicIp = exports.checkWebsite = void 0;
|
|
7
|
+
const dns_1 = require("dns");
|
|
7
8
|
const http_1 = __importDefault(require("http"));
|
|
8
9
|
const https_1 = __importDefault(require("https"));
|
|
10
|
+
const net_1 = require("net");
|
|
9
11
|
const checkWebsite = (url, timeout = 5000) => {
|
|
10
12
|
const client = url.startsWith('https:') || url.indexOf(':443/') > 0 || url.indexOf(':8443/') > 0 ? https_1.default : http_1.default;
|
|
11
13
|
const t = Date.now();
|
|
@@ -45,3 +47,46 @@ const checkWebsite = (url, timeout = 5000) => {
|
|
|
45
47
|
});
|
|
46
48
|
};
|
|
47
49
|
exports.checkWebsite = checkWebsite;
|
|
50
|
+
const dnsPublicIp = (family, timeout) => new Promise((resolve) => {
|
|
51
|
+
const resolver = new dns_1.Resolver({ timeout, tries: 1 });
|
|
52
|
+
try {
|
|
53
|
+
resolver.setServers([family === 4 ? '208.67.222.222' : '2620:119:35::35']);
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return resolve('');
|
|
57
|
+
}
|
|
58
|
+
const done = (err, addresses) => resolve(!err && addresses?.length ? addresses[0] : '');
|
|
59
|
+
if (family === 4) {
|
|
60
|
+
resolver.resolve4('myip.opendns.com', done);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
resolver.resolve6('myip.opendns.com', done);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
const webPublicIp = (family, timeout) => new Promise((resolve) => {
|
|
67
|
+
const request = https_1.default
|
|
68
|
+
.get(family === 4 ? 'https://api.ipify.org' : 'https://api6.ipify.org', { family }, (res) => {
|
|
69
|
+
let body = '';
|
|
70
|
+
res.on('data', (chunk) => {
|
|
71
|
+
body += chunk;
|
|
72
|
+
if (body.length > 64) {
|
|
73
|
+
request.destroy();
|
|
74
|
+
resolve('');
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
res.on('end', () => resolve(res.statusCode === 200 ? body.trim() : ''));
|
|
78
|
+
})
|
|
79
|
+
.on('error', () => resolve(''))
|
|
80
|
+
.setTimeout(timeout, () => {
|
|
81
|
+
request.destroy();
|
|
82
|
+
resolve('');
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
const publicIp = async (timeout = 5000) => {
|
|
86
|
+
const t = Date.now();
|
|
87
|
+
const valid = (family, ip) => ((family === 4 ? (0, net_1.isIPv4)(ip) : (0, net_1.isIPv6)(ip)) ? ip : '');
|
|
88
|
+
const lookup = async (family) => valid(family, await dnsPublicIp(family, timeout)) || valid(family, await webPublicIp(family, timeout));
|
|
89
|
+
const [ip4, ip6] = await Promise.all([lookup(4), lookup(6)]);
|
|
90
|
+
return { ip4, ip6, ms: Date.now() - t };
|
|
91
|
+
};
|
|
92
|
+
exports.publicIp = publicIp;
|