first commit

This commit is contained in:
jefferyzhao
2025-07-31 17:44:12 +08:00
commit b9bdc8598b
42390 changed files with 4467935 additions and 0 deletions

53
node_modules/internal-ip/index.d.ts generated vendored Normal file
View File

@ -0,0 +1,53 @@
interface v6 {
/**
* @returns The IPv6 address of the internet-facing interface, as determined from the default gateway. When the address cannot be determined for any reason, `null` will be returned.
*
* @example
*
* console.log(await internalIp.v6());
* //=> 'fe80::1'
*/
(): Promise<string>;
/**
* @returns The IPv6 address of the internet-facing interface, as determined from the default gateway. When the address cannot be determined for any reason, `null` will be returned.
*
* @example
*
* console.log(internalIp.v6.sync());
* //=> 'fe80::1'
*/
sync(): string;
}
interface v4 {
/**
* @returns The IPv4 address of the internet-facing interface, as determined from the default gateway. When the address cannot be determined for any reason, `null` will be returned.
*
* @example
*
* console.log(await internalIp.v4())
* //=> '10.0.0.79'
*/
(): Promise<string>;
/**
* @returns The IPv4 address of the internet-facing interface, as determined from the default gateway. When the address cannot be determined for any reason, `null` will be returned.
*
* @example
*
* console.log(internalIp.v4.sync())
* //=> '10.0.0.79'
*/
sync(): string;
}
declare const internalIp: {
v6: v6;
v4: v4;
// TODO: Remove this for the next major release
default: typeof internalIp;
};
export = internalIp;

51
node_modules/internal-ip/index.js generated vendored Normal file
View File

@ -0,0 +1,51 @@
'use strict';
const os = require('os');
const defaultGateway = require('default-gateway');
const ipaddr = require('ipaddr.js');
function findIp(gateway) {
const interfaces = os.networkInterfaces();
const gatewayIp = ipaddr.parse(gateway);
let ip;
// Look for the matching interface in all local interfaces
Object.keys(interfaces).some(name => {
return interfaces[name].some(addr => {
const prefix = ipaddr.parse(addr.netmask).prefixLengthFromSubnetMask();
const net = ipaddr.parseCIDR(`${addr.address}/${prefix}`);
if (net[0] && net[0].kind() === gatewayIp.kind() && gatewayIp.match(net)) {
ip = net[0].toString();
}
return Boolean(ip);
});
});
return ip;
}
function promise(family) {
return defaultGateway[family]().then(result => {
return findIp(result.gateway) || null;
}).catch(() => null);
}
function sync(family) {
try {
const result = defaultGateway[family].sync();
return findIp(result.gateway) || null;
} catch (error) {
return null;
}
}
const internalIp = {};
internalIp.v6 = () => promise('v6');
internalIp.v4 = () => promise('v4');
internalIp.v6.sync = () => sync('v6');
internalIp.v4.sync = () => sync('v4');
module.exports = internalIp;
// TODO: Remove this for the next major release
module.exports.default = internalIp;

9
node_modules/internal-ip/license generated vendored Normal file
View File

@ -0,0 +1,9 @@
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -0,0 +1,22 @@
Copyright (c) silverwind
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -0,0 +1,50 @@
# default-gateway
[![](https://img.shields.io/npm/v/default-gateway.svg?style=flat)](https://www.npmjs.org/package/default-gateway) [![](https://img.shields.io/npm/dm/default-gateway.svg)](https://www.npmjs.org/package/default-gateway) [![](https://api.travis-ci.org/silverwind/default-gateway.svg?style=flat)](https://travis-ci.org/silverwind/default-gateway)
> Get the default network gateway, cross-platform.
Obtains the machine's default gateway through `exec` calls to OS routing interfaces. On Linux and Android, the `ip` command must be available (usually provided by the `iproute2` package). On IBM i, the `db2util` command must be available (provided by the `db2util` package).
## Installation
```
$ npm install default-gateway
```
## Example
```js
const defaultGateway = require('default-gateway');
defaultGateway.v4().then(result => {
// result = {gateway: '1.2.3.4', interface: 'en1'}
});
defaultGateway.v6().then(result => {
// result = {gateway: '2001:db8::1', interface: 'en2'}
});
const result = defaultGateway.v4.sync();
// result = {gateway: '1.2.3.4', interface: 'en1'}
const result = defaultGateway.v6.sync();
// result = {gateway: '2001:db8::1', interface: 'en2'}
```
## API
### defaultGateway.v4()
### defaultGateway.v6()
### defaultGateway.v4.sync()
### defaultGateway.v6.sync()
Returns: `result` *Object*
- `gateway`: The IP address of the default gateway.
- `interface`: The name of the interface. On Windows, this is the network adapter name.
The `.v{4,6}()` methods return a Promise while the `.v{4,6}.sync()` variants will return the result synchronously.
The `gateway` property will always be defined on success, while `interface` can be `null` if it cannot be determined. All methods reject/throw on unexpected conditions.
## License
© [silverwind](https://github.com/silverwind), distributed under BSD licence

View File

@ -0,0 +1,46 @@
"use strict";
const net = require("net");
const execa = require("execa");
const args = {
v4: ["-4", "r"],
v6: ["-6", "r"],
};
const parse = stdout => {
let result;
(stdout || "").trim().split("\n").some(line => {
const results = /default via (.+?) dev (.+?)( |$)/.exec(line) || [];
const gateway = results[1];
const iface = results[2];
if (gateway && net.isIP(gateway)) {
result = {gateway, interface: (iface ? iface : null)};
return true;
}
});
if (!result) {
throw new Error("Unable to determine default gateway");
}
return result;
};
const promise = family => {
return execa.stdout("ip", args[family]).then(stdout => {
return parse(stdout);
});
};
const sync = family => {
const result = execa.sync("ip", args[family]);
return parse(result.stdout);
};
module.exports.v4 = () => promise("v4");
module.exports.v6 = () => promise("v6");
module.exports.v4.sync = () => sync("v4");
module.exports.v6.sync = () => sync("v6");

View File

@ -0,0 +1,48 @@
"use strict";
const net = require("net");
const execa = require("execa");
const dests = ["default", "0.0.0.0", "0.0.0.0/0", "::", "::/0"];
const args = {
v4: ["-rn", "-f", "inet"],
v6: ["-rn", "-f", "inet6"],
};
const parse = (stdout, family) => {
let result;
(stdout || "").trim().split("\n").some(line => {
const results = line.split(/ +/) || [];
const target = results[0];
const gateway = results[1];
const iface = results[family === "v4" ? 5 : 3];
if (dests.indexOf(target) !== -1 && gateway && net.isIP(gateway)) {
result = {gateway, interface: (iface ? iface : null)};
return true;
}
});
if (!result) {
throw new Error("Unable to determine default gateway");
}
return result;
};
const promise = family => {
return execa.stdout("netstat", args[family]).then(stdout => {
return parse(stdout, family);
});
};
const sync = family => {
const result = execa.sync("netstat", args[family]);
return parse(result.stdout, family);
};
module.exports.v4 = () => promise("v4");
module.exports.v6 = () => promise("v6");
module.exports.v4.sync = () => sync("v4");
module.exports.v6.sync = () => sync("v6");

View File

@ -0,0 +1,48 @@
"use strict";
const net = require("net");
const execa = require("execa");
const dests = ["default", "0.0.0.0", "0.0.0.0/0", "::", "::/0"];
const args = {
v4: ["-rn", "-f", "inet"],
v6: ["-rn", "-f", "inet6"],
};
const parse = stdout => {
let result;
(stdout || "").trim().split("\n").some(line => {
const results = line.split(/ +/) || [];
const target = results[0];
const gateway = results[1];
const iface = results[3];
if (dests.indexOf(target) !== -1 && gateway && net.isIP(gateway)) {
result = {gateway, interface: (iface ? iface : null)};
return true;
}
});
if (!result) {
throw new Error("Unable to determine default gateway");
}
return result;
};
const promise = family => {
return execa.stdout("netstat", args[family]).then(stdout => {
return parse(stdout);
});
};
const sync = family => {
const result = execa.sync("netstat", args[family]);
return parse(result.stdout);
};
module.exports.v4 = () => promise("v4");
module.exports.v6 = () => promise("v6");
module.exports.v4.sync = () => sync("v4");
module.exports.v6.sync = () => sync("v6");

View File

@ -0,0 +1,35 @@
"use strict";
const execa = require("execa");
const db2util = "/QOpenSys/pkgs/bin/db2util";
const sql = "select NEXT_HOP, LOCAL_BINDING_INTERFACE from QSYS2.NETSTAT_ROUTE_INFO where ROUTE_TYPE='DFTROUTE' and NEXT_HOP!='*DIRECT' and CONNECTION_TYPE=?";
const parse = stdout => {
let result;
try {
const resultObj = JSON.parse(stdout);
const gateway = resultObj.records[0].NEXT_HOP;
const iface = resultObj.records[0].LOCAL_BINDING_INTERFACE;
result = {gateway, iface};
} catch (err) {}
if (!result) {
throw new Error("Unable to determine default gateway");
}
return result;
};
const promise = family => {
return execa.stdout(db2util, [sql, "-p", family, "-o", "json"]).then(stdout => parse(stdout));
};
const sync = family => {
const {stdout} = execa.sync(db2util, [sql, "-p", family, "-o", "json"]);
return parse(stdout);
};
module.exports.v4 = () => promise("IPV4");
module.exports.v6 = () => promise("IPV6");
module.exports.v4.sync = () => sync("IPV4");
module.exports.v6.sync = () => sync("IPV6");

View File

@ -0,0 +1,35 @@
"use strict";
const os = require("os");
const platform = os.platform();
if ([
"android",
"darwin",
"freebsd",
"linux",
"openbsd",
"sunos",
"win32",
"aix",
].indexOf(platform) !== -1) {
let file;
if (platform === "aix") {
// AIX `netstat` output is compatible with Solaris
file = `${os.type() === "OS400" ? "ibmi" : "sunos"}.js`;
} else {
file = `${platform}.js`;
}
const m = require(`./${file}`);
module.exports.v4 = () => m.v4();
module.exports.v6 = () => m.v6();
module.exports.v4.sync = () => m.v4.sync();
module.exports.v6.sync = () => m.v6.sync();
} else {
const unsupported = () => { throw new Error(`Unsupported Platform: ${platform}`); };
module.exports.v4 = unsupported;
module.exports.v6 = unsupported;
module.exports.v4.sync = unsupported;
module.exports.v6.sync = unsupported;
}

View File

@ -0,0 +1,58 @@
"use strict";
const net = require("net");
const os = require("os");
const execa = require("execa");
const args = {
v4: ["-4", "r"],
v6: ["-6", "r"],
};
const parse = (stdout, family) => {
let result;
(stdout || "").trim().split("\n").some(line => {
const results = /default( via .+?)?( dev .+?)( |$)/.exec(line) || [];
const gateway = (results[1] || "").substring(5);
const iface = (results[2] || "").substring(5);
if (gateway && net.isIP(gateway)) { // default via 1.2.3.4 dev en0
result = {gateway, interface: (iface ? iface : null)};
return true;
} else if (iface && !gateway) { // default via dev en0
const interfaces = os.networkInterfaces();
const addresses = interfaces[iface];
if (!addresses || !addresses.length) return;
addresses.some(addr => {
if (addr.family.substring(2) === family && net.isIP(addr.address)) {
result = {gateway: addr.address, interface: (iface ? iface : null)};
return true;
}
});
}
});
if (!result) {
throw new Error("Unable to determine default gateway");
}
return result;
};
const promise = family => {
return execa.stdout("ip", args[family]).then(stdout => {
return parse(stdout, family);
});
};
const sync = family => {
const result = execa.sync("ip", args[family]);
return parse(result.stdout, family);
};
module.exports.v4 = () => promise("v4");
module.exports.v6 = () => promise("v6");
module.exports.v4.sync = () => sync("v4");
module.exports.v6.sync = () => sync("v6");

View File

@ -0,0 +1,48 @@
"use strict";
const net = require("net");
const execa = require("execa");
const dests = ["default", "0.0.0.0", "0.0.0.0/0", "::", "::/0"];
const args = {
v4: ["-rn", "-f", "inet"],
v6: ["-rn", "-f", "inet6"],
};
const parse = stdout => {
let result;
(stdout || "").trim().split("\n").some(line => {
const results = line.split(/ +/) || [];
const target = results[0];
const gateway = results[1];
const iface = results[7];
if (dests.indexOf(target) !== -1 && gateway && net.isIP(gateway)) {
result = {gateway, interface: (iface ? iface : null)};
return true;
}
});
if (!result) {
throw new Error("Unable to determine default gateway");
}
return result;
};
const promise = family => {
return execa.stdout("netstat", args[family]).then(stdout => {
return parse(stdout);
});
};
const sync = family => {
const result = execa.sync("netstat", args[family]);
return parse(result.stdout);
};
module.exports.v4 = () => promise("v4");
module.exports.v6 = () => promise("v6");
module.exports.v4.sync = () => sync("v4");
module.exports.v6.sync = () => sync("v6");

View File

@ -0,0 +1,43 @@
{
"name": "default-gateway",
"version": "4.2.0",
"description": "Get the default network gateway, cross-platform.",
"author": "silverwind <me@silverwind.io>",
"repository": "silverwind/default-gateway",
"license": "BSD-2-Clause",
"scripts": {
"test": "eslint *.js && node --pending-deprecation --trace-deprecation --throw-deprecation --trace-warnings test.js"
},
"engines": {
"node": ">=6"
},
"dependencies": {
"execa": "^1.0.0",
"ip-regex": "^2.1.0"
},
"devDependencies": {
"eslint": "^5.15.1",
"eslint-config-silverwind": "^2.1.0",
"updates": "^7.2.0",
"ver": "4.0.1"
},
"files": [
"index.js",
"android.js",
"darwin.js",
"freebsd.js",
"linux.js",
"openbsd.js",
"sunos.js",
"win32.js",
"ibmi.js"
],
"keywords": [
"default gateway",
"network",
"default",
"gateway",
"routing",
"route"
]
}

View File

@ -0,0 +1,48 @@
"use strict";
const net = require("net");
const execa = require("execa");
const dests = ["default", "0.0.0.0", "0.0.0.0/0", "::", "::/0"];
const args = {
v4: ["-rn", "-f", "inet"],
v6: ["-rn", "-f", "inet6"],
};
const parse = stdout => {
let result;
(stdout || "").trim().split("\n").some(line => {
const results = line.split(/ +/) || [];
const target = results[0];
const gateway = results[1];
const iface = results[5];
if (dests.indexOf(target) !== -1 && gateway && net.isIP(gateway)) {
result = {gateway, interface: (iface ? iface : null)};
return true;
}
});
if (!result) {
throw new Error("Unable to determine default gateway");
}
return result;
};
const promise = family => {
return execa.stdout("netstat", args[family]).then(stdout => {
return parse(stdout);
});
};
const sync = family => {
const result = execa.sync("netstat", args[family]);
return parse(result.stdout);
};
module.exports.v4 = () => promise("v4");
module.exports.v6 = () => promise("v6");
module.exports.v4.sync = () => sync("v4");
module.exports.v6.sync = () => sync("v6");

View File

@ -0,0 +1,67 @@
"use strict";
const execa = require("execa");
const ipRegex = require("ip-regex");
const gwArgs = "path Win32_NetworkAdapterConfiguration where IPEnabled=true get DefaultIPGateway,Index /format:table".split(" ");
const ifArgs = "path Win32_NetworkAdapter get Index,NetConnectionID /format:table".split(" ");
const parse = (gwTable, ifTable, family) => {
let gateway, gwid, result;
(gwTable || "").trim().split("\n").splice(1).some(line => {
const results = line.trim().split(/} +/) || [];
const gw = results[0];
const id = results[1];
gateway = (ipRegex[family]().exec((gw || "").trim()) || [])[0];
if (gateway) {
gwid = id;
return true;
}
});
(ifTable || "").trim().split("\n").splice(1).some(line => {
const i = line.indexOf(" ");
const id = line.substr(0, i).trim();
const name = line.substr(i + 1).trim();
if (id === gwid) {
result = {gateway, interface: name ? name : null};
return true;
}
});
if (!result) {
throw new Error("Unable to determine default gateway");
}
return result;
};
const spawnOpts = {
windowsHide: true,
};
const promise = family => {
return Promise.all([
execa.stdout("wmic", gwArgs, spawnOpts),
execa.stdout("wmic", ifArgs, spawnOpts),
]).then(results => {
const gwTable = results[0];
const ifTable = results[1];
return parse(gwTable, ifTable, family);
});
};
const sync = family => {
const gwTable = execa.sync("wmic", gwArgs, spawnOpts).stdout;
const ifTable = execa.sync("wmic", ifArgs, spawnOpts).stdout;
return parse(gwTable, ifTable, family);
};
module.exports.v4 = () => promise("v4");
module.exports.v6 = () => promise("v6");
module.exports.v4.sync = () => sync("v4");
module.exports.v6.sync = () => sync("v6");

43
node_modules/internal-ip/package.json generated vendored Normal file
View File

@ -0,0 +1,43 @@
{
"name": "internal-ip",
"version": "4.3.0",
"description": "Get your internal IP address",
"license": "MIT",
"repository": "sindresorhus/internal-ip",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=6"
},
"scripts": {
"test": "xo && ava && tsd"
},
"files": [
"index.js",
"index.d.ts"
],
"keywords": [
"ip",
"ipv6",
"ipv4",
"address",
"internal",
"local",
"machine",
"system",
"net",
"gateway"
],
"dependencies": {
"default-gateway": "^4.2.0",
"ipaddr.js": "^1.9.0"
},
"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}

47
node_modules/internal-ip/readme.md generated vendored Normal file
View File

@ -0,0 +1,47 @@
# internal-ip [![Build Status](https://travis-ci.org/sindresorhus/internal-ip.svg?branch=master)](https://travis-ci.org/sindresorhus/internal-ip)
> Get your internal IP address
## Install
```
$ npm install internal-ip
```
## Usage
```js
const internalIp = require('internal-ip');
(async () => {
console.log(await internalIp.v6());
//=> 'fe80::1'
console.log(await internalIp.v4());
//=> '10.0.0.79'
})();
console.log(internalIp.v6.sync())
//=> 'fe80::1'
console.log(internalIp.v4.sync())
//=> '10.0.0.79'
```
The module returns the address of the internet-facing interface, as determined from the default gateway. When the address cannot be determined for any reason, `null` will be returned.
The module relies on operating systems tools. On Linux and Android, the `ip` command must be available, which depending on distribution might not be installed by default. It is usually provided by the `iproute2` package.
## Related
- [internal-ip-cli](https://github.com/sindresorhus/internal-ip-cli) - CLI for this module
- [public-ip](https://github.com/sindresorhus/public-ip) - Get your public IP address
- [default-gateway](https://github.com/silverwind/default-gateway) - Get your default gateway address
## License
MIT © [Sindre Sorhus](https://sindresorhus.com)