@arcanewizards/net-utils 0.1.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/index.cjs +36 -0
- package/dist/index.d.cts +30 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +36 -0
- package/package.json +37 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/index.ts
|
|
2
|
+
var _os = require('os'); var _os2 = _interopRequireDefault(_os);
|
|
3
|
+
var getBroadcastAddress = (ip, netmask) => {
|
|
4
|
+
const ipParts = ip.split(".").map(Number);
|
|
5
|
+
const maskParts = netmask.split(".").map(Number);
|
|
6
|
+
const broadcastParts = ipParts.map(
|
|
7
|
+
(part, i) => part | ~(_nullishCoalesce(maskParts[i], () => ( 0))) & 255
|
|
8
|
+
);
|
|
9
|
+
return broadcastParts.join(".");
|
|
10
|
+
};
|
|
11
|
+
var getNetworkInterfaces = async () => {
|
|
12
|
+
const interfaces = _os2.default.networkInterfaces();
|
|
13
|
+
const results = {};
|
|
14
|
+
for (const name of Object.keys(interfaces)) {
|
|
15
|
+
const addrs = interfaces[name];
|
|
16
|
+
if (!addrs) continue;
|
|
17
|
+
for (const addr of addrs) {
|
|
18
|
+
if (addr.family === "IPv4") {
|
|
19
|
+
const broadcastAddress = getBroadcastAddress(
|
|
20
|
+
addr.address,
|
|
21
|
+
addr.netmask
|
|
22
|
+
);
|
|
23
|
+
results[name] = {
|
|
24
|
+
name,
|
|
25
|
+
address: addr.address,
|
|
26
|
+
internal: addr.internal,
|
|
27
|
+
broadcastAddress
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return results;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
exports.getNetworkInterfaces = getNetworkInterfaces;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
type NetworkTarget = {
|
|
2
|
+
type: 'host';
|
|
3
|
+
host: string;
|
|
4
|
+
} | {
|
|
5
|
+
type: 'interface';
|
|
6
|
+
interface: string;
|
|
7
|
+
};
|
|
8
|
+
type ConnectionConfig = NetworkTarget & {
|
|
9
|
+
port?: number;
|
|
10
|
+
};
|
|
11
|
+
type NetworkInterface = {
|
|
12
|
+
name: string;
|
|
13
|
+
address: string;
|
|
14
|
+
internal: boolean;
|
|
15
|
+
broadcastAddress: string;
|
|
16
|
+
};
|
|
17
|
+
type NetworkPortStatus = {
|
|
18
|
+
direction: 'input' | 'output' | 'both';
|
|
19
|
+
target: NetworkTarget;
|
|
20
|
+
port: number | {
|
|
21
|
+
from: number;
|
|
22
|
+
to: number;
|
|
23
|
+
};
|
|
24
|
+
status: 'disabled' | 'connecting' | 'active' | 'error';
|
|
25
|
+
errors?: string[];
|
|
26
|
+
warnings?: string[];
|
|
27
|
+
};
|
|
28
|
+
declare const getNetworkInterfaces: () => Promise<Record<string, NetworkInterface>>;
|
|
29
|
+
|
|
30
|
+
export { type ConnectionConfig, type NetworkInterface, type NetworkPortStatus, type NetworkTarget, getNetworkInterfaces };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
type NetworkTarget = {
|
|
2
|
+
type: 'host';
|
|
3
|
+
host: string;
|
|
4
|
+
} | {
|
|
5
|
+
type: 'interface';
|
|
6
|
+
interface: string;
|
|
7
|
+
};
|
|
8
|
+
type ConnectionConfig = NetworkTarget & {
|
|
9
|
+
port?: number;
|
|
10
|
+
};
|
|
11
|
+
type NetworkInterface = {
|
|
12
|
+
name: string;
|
|
13
|
+
address: string;
|
|
14
|
+
internal: boolean;
|
|
15
|
+
broadcastAddress: string;
|
|
16
|
+
};
|
|
17
|
+
type NetworkPortStatus = {
|
|
18
|
+
direction: 'input' | 'output' | 'both';
|
|
19
|
+
target: NetworkTarget;
|
|
20
|
+
port: number | {
|
|
21
|
+
from: number;
|
|
22
|
+
to: number;
|
|
23
|
+
};
|
|
24
|
+
status: 'disabled' | 'connecting' | 'active' | 'error';
|
|
25
|
+
errors?: string[];
|
|
26
|
+
warnings?: string[];
|
|
27
|
+
};
|
|
28
|
+
declare const getNetworkInterfaces: () => Promise<Record<string, NetworkInterface>>;
|
|
29
|
+
|
|
30
|
+
export { type ConnectionConfig, type NetworkInterface, type NetworkPortStatus, type NetworkTarget, getNetworkInterfaces };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import os from "os";
|
|
3
|
+
var getBroadcastAddress = (ip, netmask) => {
|
|
4
|
+
const ipParts = ip.split(".").map(Number);
|
|
5
|
+
const maskParts = netmask.split(".").map(Number);
|
|
6
|
+
const broadcastParts = ipParts.map(
|
|
7
|
+
(part, i) => part | ~(maskParts[i] ?? 0) & 255
|
|
8
|
+
);
|
|
9
|
+
return broadcastParts.join(".");
|
|
10
|
+
};
|
|
11
|
+
var getNetworkInterfaces = async () => {
|
|
12
|
+
const interfaces = os.networkInterfaces();
|
|
13
|
+
const results = {};
|
|
14
|
+
for (const name of Object.keys(interfaces)) {
|
|
15
|
+
const addrs = interfaces[name];
|
|
16
|
+
if (!addrs) continue;
|
|
17
|
+
for (const addr of addrs) {
|
|
18
|
+
if (addr.family === "IPv4") {
|
|
19
|
+
const broadcastAddress = getBroadcastAddress(
|
|
20
|
+
addr.address,
|
|
21
|
+
addr.netmask
|
|
22
|
+
);
|
|
23
|
+
results[name] = {
|
|
24
|
+
name,
|
|
25
|
+
address: addr.address,
|
|
26
|
+
internal: addr.internal,
|
|
27
|
+
broadcastAddress
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return results;
|
|
33
|
+
};
|
|
34
|
+
export {
|
|
35
|
+
getNetworkInterfaces
|
|
36
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@arcanewizards/net-utils",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"@arcanewizards/source": "./src/index.ts",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.cjs"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "rm -rf dist && tsup && check-export-map",
|
|
20
|
+
"check:types": "tsc --noEmit",
|
|
21
|
+
"format:fix": "cd .. && pnpm format:fix",
|
|
22
|
+
"lint": "eslint . --max-warnings 0",
|
|
23
|
+
"lint:fix": "eslint --fix ."
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@arcanewizards/eslint-config": "workspace:^",
|
|
27
|
+
"@arcanewizards/typescript-config": "workspace:^",
|
|
28
|
+
"@types/node": "^25.0.3",
|
|
29
|
+
"check-export-map": "^1.3.1",
|
|
30
|
+
"eslint": "^9",
|
|
31
|
+
"tsup": "^8.1.0",
|
|
32
|
+
"typescript": "^5.7.3"
|
|
33
|
+
},
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=22.12.0 || >=23.1.0"
|
|
36
|
+
}
|
|
37
|
+
}
|