Project Init

This commit is contained in:
Muluhabt
2026-05-29 15:23:46 +03:00
commit 2fbc557aac
67387 changed files with 6063341 additions and 0 deletions

BIN
node_modules/address/.DS_Store generated vendored Normal file

Binary file not shown.

22
node_modules/address/LICENSE.txt generated vendored Normal file
View File

@@ -0,0 +1,22 @@
This software is licensed under the MIT License.
Copyright (C) 2013 - 2014 fengmk2 <fengmk2@gmail.com>
Copyright (C) 2015 - present node-modules and other contributors.
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.

173
node_modules/address/README.md generated vendored Normal file
View File

@@ -0,0 +1,173 @@
# address
[![NPM version][npm-image]][npm-url]
[![Node.js CI](https://github.com/node-modules/address/actions/workflows/nodejs.yml/badge.svg)](https://github.com/node-modules/address/actions/workflows/nodejs.yml)
[![Test coverage][coveralls-image]][coveralls-url]
[![npm download][download-image]][download-url]
[npm-image]: https://img.shields.io/npm/v/address.svg?style=flat-square
[npm-url]: https://npmjs.org/package/address
[coveralls-image]: https://img.shields.io/coveralls/node-modules/address.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/node-modules/address?branch=master
[download-image]: https://img.shields.io/npm/dm/address.svg?style=flat-square
[download-url]: https://npmjs.org/package/address
Get current machine IPv4, IPv6, MAC and DNS servers.
DNS servers receive from `/etc/resolv.conf`.
## Install
```bash
npm install address
```
## Usage
Get IP is sync and get MAC is async for now.
- esm & typescript
```ts
import { ip, ipv6, mac } from 'address';
// default interface 'eth' on linux, 'en' on osx.
ip(); // '192.168.0.2'
ipv6(); // 'fe80::7aca:39ff:feb0:e67d'
mac(function (err, addr) {
console.log(addr); // '78:ca:39:b0:e6:7d'
});
// local loopback
ip('lo'); // '127.0.0.1'
// vboxnet MAC
mac('vboxnet', function (err, addr) {
console.log(addr); // '0a:00:27:00:00:00'
});
```
- commonjs
```js
const { ip, ipv6, mac } = require('address');
// default interface 'eth' on linux, 'en' on osx.
ip(); // '192.168.0.2'
ipv6(); // 'fe80::7aca:39ff:feb0:e67d'
mac(function (err, addr) {
console.log(addr); // '78:ca:39:b0:e6:7d'
});
// local loopback
ip('lo'); // '127.0.0.1'
// vboxnet MAC
mac('vboxnet', function (err, addr) {
console.log(addr); // '0a:00:27:00:00:00'
});
```
### Get all addresses: IPv4, IPv6 and MAC
- esm & typescript
```ts
import { address } from 'address';
address((err, addrs) => {
console.log(addrs.ip, addrs.ipv6, addrs.mac);
// '192.168.0.2', 'fe80::7aca:39ff:feb0:e67d', '78:ca:39:b0:e6:7d'
});
address('vboxnet', (err, addrs) => {
console.log(addrs.ip, addrs.ipv6, addrs.mac);
// '192.168.56.1', null, '0a:00:27:00:00:00'
});
```
- commonjs
```js
const { address } = require('address');
address((err, addrs) => {
console.log(addrs.ip, addrs.ipv6, addrs.mac);
// '192.168.0.2', 'fe80::7aca:39ff:feb0:e67d', '78:ca:39:b0:e6:7d'
});
address('vboxnet', (err, addrs) => {
console.log(addrs.ip, addrs.ipv6, addrs.mac);
// '192.168.56.1', null, '0a:00:27:00:00:00'
});
```
### Get an interface info with family
- esm & typescript
```ts
import { getInterfaceAddress } from 'address';
getInterfaceAddress('IPv4', 'eth1');
// { address: '192.168.1.1', family: 'IPv4', mac: '78:ca:39:b0:e6:7d' }
```
- commonjs
```js
const { getInterfaceAddress } = require('address');
getInterfaceAddress('IPv4', 'eth1');
// { address: '192.168.1.1', family: 'IPv4', mac: '78:ca:39:b0:e6:7d' }
```
### Get DNS servers
- esm & typescript
```js
import { dns } from 'address';
dns((err, servers) => {
console.log(servers);
// ['10.13.2.1', '10.13.2.6']
});
```
- commonjs
```js
const { dns } = require('address');
dns((err, servers) => {
console.log(servers);
// ['10.13.2.1', '10.13.2.6']
});
```
### Promise style apis
```ts
import { address, mac, dns } from 'address/promises';
const addr = await address();
const macAddress = await mac();
const servers = await dns();
```
## License
[MIT](LICENSE.txt)
<!-- GITCONTRIBUTOR_START -->
## Contributors
|[<img src="https://avatars.githubusercontent.com/u/156269?v=4" width="100px;"/><br/><sub><b>fengmk2</b></sub>](https://github.com/fengmk2)<br/>|[<img src="https://avatars.githubusercontent.com/u/1147375?v=4" width="100px;"/><br/><sub><b>alsotang</b></sub>](https://github.com/alsotang)<br/>|[<img src="https://avatars.githubusercontent.com/u/10237910?v=4" width="100px;"/><br/><sub><b>jkelleyrtp</b></sub>](https://github.com/jkelleyrtp)<br/>|[<img src="https://avatars.githubusercontent.com/u/63956?v=4" width="100px;"/><br/><sub><b>slyon</b></sub>](https://github.com/slyon)<br/>|[<img src="https://avatars.githubusercontent.com/u/1409643?v=4" width="100px;"/><br/><sub><b>mariodu</b></sub>](https://github.com/mariodu)<br/>|[<img src="https://avatars.githubusercontent.com/u/11351322?v=4" width="100px;"/><br/><sub><b>mathieutu</b></sub>](https://github.com/mathieutu)<br/>|
| :---: | :---: | :---: | :---: | :---: | :---: |
[<img src="https://avatars.githubusercontent.com/u/2139038?v=4" width="100px;"/><br/><sub><b>zhangyuheng</b></sub>](https://github.com/zhangyuheng)<br/>|[<img src="https://avatars.githubusercontent.com/u/32174276?v=4" width="100px;"/><br/><sub><b>semantic-release-bot</b></sub>](https://github.com/semantic-release-bot)<br/>|[<img src="https://avatars.githubusercontent.com/u/1400114?v=4" width="100px;"/><br/><sub><b>coolme200</b></sub>](https://github.com/coolme200)<br/>|[<img src="https://avatars.githubusercontent.com/u/5856440?v=4" width="100px;"/><br/><sub><b>whxaxes</b></sub>](https://github.com/whxaxes)<br/>
This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Fri Sep 22 2023 20:49:32 GMT+0800`.
<!-- GITCONTRIBUTOR_END -->

46
node_modules/address/dist/commonjs/address.d.ts generated vendored Normal file
View File

@@ -0,0 +1,46 @@
/// <reference types="node" />
import os from 'node:os';
export declare const MAC_RE: RegExp;
export declare const MAC_IP_RE: RegExp;
export interface Address {
ip?: string;
ipv6?: string;
mac?: string;
}
export type AddressCallback = (err: Error | null, addr: Address) => void;
export type MacCallback = (err?: Error | null, addr?: string | null) => void;
export type DnsCallback = (err?: Error | null, servers?: string[]) => void;
export declare function getInterfaceAddress(family?: string, name?: string): os.NetworkInterfaceInfo | undefined;
/**
* Get current machine IPv4
*
* interfaceName: interface name, default is 'eth' on linux, 'en' on mac os.
*/
export declare function ip(interfaceName?: string): string | undefined;
/**
* Get current machine IPv6
*
* interfaceName: interface name, default is 'eth' on linux, 'en' on mac os.
*/
export declare function ipv6(interfaceName?: string): string | undefined;
/**
* Get current machine MAC address
*
* interfaceName: name, default is 'eth' on linux, 'en' on mac os.
*/
export declare function mac(callback: MacCallback): void;
export declare function mac(interfaceName: string, callback: MacCallback): void;
/**
* Get DNS servers.
*
* filepath: resolv config file path. default is '/etc/resolv.conf'.
*/
export declare function dns(callback: DnsCallback): void;
export declare function dns(filepath: string, callback: DnsCallback): void;
/**
* Get all addresses.
*
* interfaceName: interface name, default is 'eth' on linux, 'en' on mac os.
*/
export declare function address(callback: AddressCallback): void;
export declare function address(interfaceName: string, callback: AddressCallback): void;

256
node_modules/address/dist/commonjs/address.js generated vendored Normal file

File diff suppressed because one or more lines are too long

3
node_modules/address/dist/commonjs/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,3 @@
import { address } from './address.js';
export * from './address.js';
export default address;

20
node_modules/address/dist/commonjs/index.js generated vendored Normal file
View File

@@ -0,0 +1,20 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
const address_js_1 = require("./address.js");
__exportStar(require("./address.js"), exports);
exports.default = address_js_1.address;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7OztBQUFBLDZDQUF1QztBQUV2QywrQ0FBNkI7QUFDN0Isa0JBQWUsb0JBQU8sQ0FBQyJ9

3
node_modules/address/dist/commonjs/package.json generated vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"type": "commonjs"
}

4
node_modules/address/dist/commonjs/promises.d.ts generated vendored Normal file
View File

@@ -0,0 +1,4 @@
import { Address } from './address.js';
export declare function address(interfaceName?: string): Promise<Address>;
export declare function mac(interfaceName?: string): Promise<string | null>;
export declare function dns(filepath?: string): Promise<string[]>;

35
node_modules/address/dist/commonjs/promises.js generated vendored Normal file
View File

@@ -0,0 +1,35 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.dns = exports.mac = exports.address = void 0;
const address_js_1 = require("./address.js");
function address(interfaceName) {
return new Promise((resolve, reject) => {
(0, address_js_1.address)(interfaceName || '', (err, address) => {
if (err)
return reject(err);
resolve(address);
});
});
}
exports.address = address;
function mac(interfaceName) {
return new Promise((resolve, reject) => {
(0, address_js_1.mac)(interfaceName || '', (err, address) => {
if (err)
return reject(err);
resolve(address || null);
});
});
}
exports.mac = mac;
function dns(filepath) {
return new Promise((resolve, reject) => {
(0, address_js_1.dns)(filepath || '', (err, servers) => {
if (err)
return reject(err);
resolve(servers || []);
});
});
}
exports.dns = dns;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHJvbWlzZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvcHJvbWlzZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBQUEsNkNBSXNCO0FBRXRCLFNBQWdCLE9BQU8sQ0FBQyxhQUFzQjtJQUM1QyxPQUFPLElBQUksT0FBTyxDQUFVLENBQUMsT0FBTyxFQUFFLE1BQU0sRUFBRSxFQUFFO1FBQzlDLElBQUEsb0JBQVUsRUFBQyxhQUFhLElBQUksRUFBRSxFQUFFLENBQUMsR0FBRyxFQUFFLE9BQU8sRUFBRSxFQUFFO1lBQy9DLElBQUksR0FBRztnQkFBRSxPQUFPLE1BQU0sQ0FBQyxHQUFHLENBQUMsQ0FBQztZQUM1QixPQUFPLENBQUMsT0FBTyxDQUFDLENBQUM7UUFDbkIsQ0FBQyxDQUFDLENBQUM7SUFDTCxDQUFDLENBQUMsQ0FBQztBQUNMLENBQUM7QUFQRCwwQkFPQztBQUVELFNBQWdCLEdBQUcsQ0FBQyxhQUFzQjtJQUN4QyxPQUFPLElBQUksT0FBTyxDQUFnQixDQUFDLE9BQU8sRUFBRSxNQUFNLEVBQUUsRUFBRTtRQUNwRCxJQUFBLGdCQUFNLEVBQUMsYUFBYSxJQUFJLEVBQUUsRUFBRSxDQUFDLEdBQUcsRUFBRSxPQUFPLEVBQUUsRUFBRTtZQUMzQyxJQUFJLEdBQUc7Z0JBQUUsT0FBTyxNQUFNLENBQUMsR0FBRyxDQUFDLENBQUM7WUFDNUIsT0FBTyxDQUFDLE9BQU8sSUFBSSxJQUFJLENBQUMsQ0FBQztRQUMzQixDQUFDLENBQUMsQ0FBQztJQUNMLENBQUMsQ0FBQyxDQUFDO0FBQ0wsQ0FBQztBQVBELGtCQU9DO0FBRUQsU0FBZ0IsR0FBRyxDQUFDLFFBQWlCO0lBQ25DLE9BQU8sSUFBSSxPQUFPLENBQVcsQ0FBQyxPQUFPLEVBQUUsTUFBTSxFQUFFLEVBQUU7UUFDL0MsSUFBQSxnQkFBTSxFQUFDLFFBQVEsSUFBSSxFQUFFLEVBQUUsQ0FBQyxHQUFHLEVBQUUsT0FBTyxFQUFFLEVBQUU7WUFDdEMsSUFBSSxHQUFHO2dCQUFFLE9BQU8sTUFBTSxDQUFDLEdBQUcsQ0FBQyxDQUFDO1lBQzVCLE9BQU8sQ0FBQyxPQUFPLElBQUksRUFBRSxDQUFDLENBQUM7UUFDekIsQ0FBQyxDQUFDLENBQUM7SUFDTCxDQUFDLENBQUMsQ0FBQztBQUNMLENBQUM7QUFQRCxrQkFPQyJ9

46
node_modules/address/dist/esm/address.d.ts generated vendored Normal file
View File

@@ -0,0 +1,46 @@
/// <reference types="node" resolution-mode="require"/>
import os from 'node:os';
export declare const MAC_RE: RegExp;
export declare const MAC_IP_RE: RegExp;
export interface Address {
ip?: string;
ipv6?: string;
mac?: string;
}
export type AddressCallback = (err: Error | null, addr: Address) => void;
export type MacCallback = (err?: Error | null, addr?: string | null) => void;
export type DnsCallback = (err?: Error | null, servers?: string[]) => void;
export declare function getInterfaceAddress(family?: string, name?: string): os.NetworkInterfaceInfo | undefined;
/**
* Get current machine IPv4
*
* interfaceName: interface name, default is 'eth' on linux, 'en' on mac os.
*/
export declare function ip(interfaceName?: string): string | undefined;
/**
* Get current machine IPv6
*
* interfaceName: interface name, default is 'eth' on linux, 'en' on mac os.
*/
export declare function ipv6(interfaceName?: string): string | undefined;
/**
* Get current machine MAC address
*
* interfaceName: name, default is 'eth' on linux, 'en' on mac os.
*/
export declare function mac(callback: MacCallback): void;
export declare function mac(interfaceName: string, callback: MacCallback): void;
/**
* Get DNS servers.
*
* filepath: resolv config file path. default is '/etc/resolv.conf'.
*/
export declare function dns(callback: DnsCallback): void;
export declare function dns(filepath: string, callback: DnsCallback): void;
/**
* Get all addresses.
*
* interfaceName: interface name, default is 'eth' on linux, 'en' on mac os.
*/
export declare function address(callback: AddressCallback): void;
export declare function address(interfaceName: string, callback: AddressCallback): void;

244
node_modules/address/dist/esm/address.js generated vendored Normal file

File diff suppressed because one or more lines are too long

3
node_modules/address/dist/esm/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,3 @@
import { address } from './address.js';
export * from './address.js';
export default address;

4
node_modules/address/dist/esm/index.js generated vendored Normal file
View File

@@ -0,0 +1,4 @@
import { address } from './address.js';
export * from './address.js';
export default address;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLE9BQU8sRUFBRSxNQUFNLGNBQWMsQ0FBQztBQUV2QyxjQUFjLGNBQWMsQ0FBQztBQUM3QixlQUFlLE9BQU8sQ0FBQyJ9

3
node_modules/address/dist/esm/package.json generated vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"type": "module"
}

4
node_modules/address/dist/esm/promises.d.ts generated vendored Normal file
View File

@@ -0,0 +1,4 @@
import { Address } from './address.js';
export declare function address(interfaceName?: string): Promise<Address>;
export declare function mac(interfaceName?: string): Promise<string | null>;
export declare function dns(filepath?: string): Promise<string[]>;

29
node_modules/address/dist/esm/promises.js generated vendored Normal file
View File

@@ -0,0 +1,29 @@
import { address as getAddress, mac as getMac, dns as getDns, } from './address.js';
export function address(interfaceName) {
return new Promise((resolve, reject) => {
getAddress(interfaceName || '', (err, address) => {
if (err)
return reject(err);
resolve(address);
});
});
}
export function mac(interfaceName) {
return new Promise((resolve, reject) => {
getMac(interfaceName || '', (err, address) => {
if (err)
return reject(err);
resolve(address || null);
});
});
}
export function dns(filepath) {
return new Promise((resolve, reject) => {
getDns(filepath || '', (err, servers) => {
if (err)
return reject(err);
resolve(servers || []);
});
});
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHJvbWlzZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvcHJvbWlzZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUNJLE9BQU8sSUFBSSxVQUFVLEVBQzlCLEdBQUcsSUFBSSxNQUFNLEVBQ2IsR0FBRyxJQUFJLE1BQU0sR0FDZCxNQUFNLGNBQWMsQ0FBQztBQUV0QixNQUFNLFVBQVUsT0FBTyxDQUFDLGFBQXNCO0lBQzVDLE9BQU8sSUFBSSxPQUFPLENBQVUsQ0FBQyxPQUFPLEVBQUUsTUFBTSxFQUFFLEVBQUU7UUFDOUMsVUFBVSxDQUFDLGFBQWEsSUFBSSxFQUFFLEVBQUUsQ0FBQyxHQUFHLEVBQUUsT0FBTyxFQUFFLEVBQUU7WUFDL0MsSUFBSSxHQUFHO2dCQUFFLE9BQU8sTUFBTSxDQUFDLEdBQUcsQ0FBQyxDQUFDO1lBQzVCLE9BQU8sQ0FBQyxPQUFPLENBQUMsQ0FBQztRQUNuQixDQUFDLENBQUMsQ0FBQztJQUNMLENBQUMsQ0FBQyxDQUFDO0FBQ0wsQ0FBQztBQUVELE1BQU0sVUFBVSxHQUFHLENBQUMsYUFBc0I7SUFDeEMsT0FBTyxJQUFJLE9BQU8sQ0FBZ0IsQ0FBQyxPQUFPLEVBQUUsTUFBTSxFQUFFLEVBQUU7UUFDcEQsTUFBTSxDQUFDLGFBQWEsSUFBSSxFQUFFLEVBQUUsQ0FBQyxHQUFHLEVBQUUsT0FBTyxFQUFFLEVBQUU7WUFDM0MsSUFBSSxHQUFHO2dCQUFFLE9BQU8sTUFBTSxDQUFDLEdBQUcsQ0FBQyxDQUFDO1lBQzVCLE9BQU8sQ0FBQyxPQUFPLElBQUksSUFBSSxDQUFDLENBQUM7UUFDM0IsQ0FBQyxDQUFDLENBQUM7SUFDTCxDQUFDLENBQUMsQ0FBQztBQUNMLENBQUM7QUFFRCxNQUFNLFVBQVUsR0FBRyxDQUFDLFFBQWlCO0lBQ25DLE9BQU8sSUFBSSxPQUFPLENBQVcsQ0FBQyxPQUFPLEVBQUUsTUFBTSxFQUFFLEVBQUU7UUFDL0MsTUFBTSxDQUFDLFFBQVEsSUFBSSxFQUFFLEVBQUUsQ0FBQyxHQUFHLEVBQUUsT0FBTyxFQUFFLEVBQUU7WUFDdEMsSUFBSSxHQUFHO2dCQUFFLE9BQU8sTUFBTSxDQUFDLEdBQUcsQ0FBQyxDQUFDO1lBQzVCLE9BQU8sQ0FBQyxPQUFPLElBQUksRUFBRSxDQUFDLENBQUM7UUFDekIsQ0FBQyxDQUFDLENBQUM7SUFDTCxDQUFDLENBQUMsQ0FBQztBQUNMLENBQUMifQ==

85
node_modules/address/package.json generated vendored Normal file
View File

@@ -0,0 +1,85 @@
{
"name": "address",
"version": "2.0.3",
"description": "Get current machine IP, MAC and DNS servers.",
"scripts": {
"lint": "eslint src test --ext .ts",
"pretest": "npm run lint -- --fix && npm run prepublishOnly",
"test": "egg-bin test",
"preci": "npm run lint && npm run prepublishOnly && attw --pack --ignore-rules no-resolution",
"ci": "egg-bin cov",
"contributor": "git-contributor",
"prepublishOnly": "tshy && tshy-after"
},
"devDependencies": {
"@arethetypeswrong/cli": "*",
"@eggjs/tsconfig": "^1.3.3",
"@types/mocha": "^10.0.1",
"@types/node": "^20.6.3",
"egg-bin": "^6.5.2",
"eslint": "^8.49.0",
"eslint-config-egg": "^13.0.0",
"git-contributor": "^2.1.5",
"mm": "^3.3.0",
"runscript": "^1.5.3",
"tshy": "^1.1.1",
"tshy-after": "^1.0.0",
"typescript": "^5.2.2"
},
"repository": {
"type": "git",
"url": "git://github.com/node-modules/address.git"
},
"keywords": [
"address",
"ip",
"ipv4",
"mac"
],
"engines": {
"node": ">= 16.0.0"
},
"author": "fengmk2 <fengmk2@gmail.com>",
"license": "MIT",
"files": [
"dist",
"src"
],
"type": "module",
"tshy": {
"exports": {
"./package.json": "./package.json",
"./promises": "./src/promises.ts",
".": "./src/index.ts"
}
},
"exports": {
"./package.json": "./package.json",
"./promises": {
"import": {
"source": "./src/promises.ts",
"types": "./dist/esm/promises.d.ts",
"default": "./dist/esm/promises.js"
},
"require": {
"source": "./src/promises.ts",
"types": "./dist/commonjs/promises.d.ts",
"default": "./dist/commonjs/promises.js"
}
},
".": {
"import": {
"source": "./src/index.ts",
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"source": "./src/index.ts",
"types": "./dist/commonjs/index.d.ts",
"default": "./dist/commonjs/index.js"
}
}
},
"types": "./dist/commonjs/index.d.ts",
"main": "./dist/commonjs/index.js"
}

297
node_modules/address/src/address.ts generated vendored Normal file
View File

@@ -0,0 +1,297 @@
import os from 'node:os';
import fs from 'node:fs/promises';
import childProcess from 'node:child_process';
const DEFAULT_RESOLV_FILE = '/etc/resolv.conf';
// osx start line 'en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500'
// linux start line 'eth0 Link encap:Ethernet HWaddr 00:16:3E:00:0A:29 '
const MAC_OSX_START_LINE = /^(\w+)\:\s+flags=/;
const MAC_LINUX_START_LINE = /^(\w+)\s{2,}link encap:\w+/i;
// ether 78:ca:39:b0:e6:7d
// HWaddr 00:16:3E:00:0A:29
export const MAC_RE = /(?:ether|HWaddr)\s+((?:[a-z0-9]{2}\:){5}[a-z0-9]{2})/i;
// osx: inet 192.168.2.104 netmask 0xffffff00 broadcast 192.168.2.255
// linux: inet addr:10.125.5.202 Bcast:10.125.15.255 Mask:255.255.240.0
export const MAC_IP_RE = /inet\s(?:addr\:)?(\d+\.\d+\.\d+\.\d+)/;
export interface Address {
ip?: string;
ipv6?: string;
mac?: string;
}
export type AddressCallback = (err: Error | null, addr: Address) => void;
export type MacCallback = (err?: Error | null, addr?: string | null) => void;
export type DnsCallback = (err?: Error | null, servers?: string[]) => void;
function getDefaultInterfaceName() {
let val: string | undefined = 'eth';
const platform = os.platform();
if (platform === 'darwin') {
val = 'en';
} else if (platform === 'win32') {
val = undefined;
}
return val;
}
function getIfconfigCMD() {
if (os.platform() === 'win32') {
return 'ipconfig/all';
}
return '/sbin/ifconfig';
}
// typeof os.networkInterfaces family is a number (v18.0.0)
// types: 'IPv4' | 'IPv6' => 4 | 6
// @see https://github.com/nodejs/node/issues/42861
function matchName(actualFamily: string | number, expectedFamily: string | number) {
if (expectedFamily === 'IPv4') {
return actualFamily === 'IPv4' || actualFamily === 4;
}
if (expectedFamily === 'IPv6') {
return actualFamily === 'IPv6' || actualFamily === 6;
}
return actualFamily === expectedFamily;
}
function findAddressFromInterface(items: os.NetworkInterfaceInfo[], expectedFamily: string | number,
ignoreLoAddress = false) {
let firstMatchItem;
for (const item of items) {
if (matchName(item.family, expectedFamily)) {
if (ignoreLoAddress && item.address.startsWith('127.')) {
continue;
}
if (expectedFamily === 'IPv6') {
// find the scopeid = 0 item
if (item.scopeid === 0) return item;
if (!firstMatchItem) {
firstMatchItem = item;
}
} else {
return item;
}
}
}
return firstMatchItem;
}
export function getInterfaceAddress(family?: string, name?: string) {
const interfaces = os.networkInterfaces();
const noName = !name;
name = name || getDefaultInterfaceName();
family = family || 'IPv4';
if (name) {
for (let i = -1; i < 8; i++) {
const interfaceName = name + (i >= 0 ? i : ''); // support 'lo' and 'lo0'
const items = interfaces[interfaceName];
if (items) {
const item = findAddressFromInterface(items, family);
if (item) {
return item;
}
}
}
}
if (noName) {
// filter all loopback or local addresses
for (const k in interfaces) {
const items = interfaces[k];
if (items) {
// all 127 addresses are local and should be ignored
const item = findAddressFromInterface(items, family, true);
if (item) {
return item;
}
}
}
}
return;
}
/**
* Get current machine IPv4
*
* interfaceName: interface name, default is 'eth' on linux, 'en' on mac os.
*/
export function ip(interfaceName?: string) {
const item = getInterfaceAddress('IPv4', interfaceName);
return item?.address;
}
/**
* Get current machine IPv6
*
* interfaceName: interface name, default is 'eth' on linux, 'en' on mac os.
*/
export function ipv6(interfaceName?: string) {
const item = getInterfaceAddress('IPv6', interfaceName);
return item?.address;
}
function getMAC(content: string, interfaceName: string, matchIP: string) {
const lines = content.split('\n');
for (let i = 0; i < lines.length; i++) {
let line = lines[i].trimEnd();
const m = MAC_OSX_START_LINE.exec(line) || MAC_LINUX_START_LINE.exec(line);
if (!m) {
continue;
}
// check interface name
const name = m[1];
if (name.indexOf(interfaceName) !== 0) {
continue;
}
let ip: string | null = null;
let mac: string | null = null;
let match = MAC_RE.exec(line);
if (match) {
mac = match[1];
}
i++;
// eslint-disable-next-line no-constant-condition
while (true) {
line = lines[i];
if (!line || MAC_OSX_START_LINE.exec(line) || MAC_LINUX_START_LINE.exec(line)) {
i--;
break; // hit next interface, handle next interface
}
if (!mac) {
match = MAC_RE.exec(line);
if (match) {
mac = match[1];
}
}
if (!ip) {
match = MAC_IP_RE.exec(line);
if (match) {
ip = match[1];
}
}
i++;
}
if (ip === matchIP) {
return mac;
}
}
return null;
}
/**
* Get current machine MAC address
*
* interfaceName: name, default is 'eth' on linux, 'en' on mac os.
*/
export function mac(callback: MacCallback): void;
export function mac(interfaceName: string, callback: MacCallback): void;
export function mac(interfaceNameOrCallback: string | MacCallback, callback?: MacCallback) {
let interfaceName: string | undefined;
if (typeof interfaceNameOrCallback === 'function') {
callback = interfaceNameOrCallback;
} else {
interfaceName = interfaceNameOrCallback;
}
interfaceName = interfaceName || getDefaultInterfaceName();
const item = getInterfaceAddress('IPv4', interfaceName);
if (!item) {
return callback!();
}
// https://github.com/nodejs/node/issues/13581
// bug in node 7.x and <= 8.4.0
if (!process.env.CI && (item.mac === 'ff:00:00:00:00:00' || item.mac === '00:00:00:00:00:00')) {
// wrong address, ignore it
item.mac = '';
}
if (item.mac) {
return callback!(null, item.mac);
}
childProcess.exec(getIfconfigCMD(), { timeout: 5000 }, (err, stdout) => {
if (err || !stdout) {
return callback!(err);
}
if (!interfaceName) {
return callback!();
}
const mac = getMAC(stdout || '', interfaceName, item.address);
callback!(null, mac);
});
}
// nameserver 172.24.102.254
const DNS_SERVER_RE = /^nameserver\s+(\d+\.\d+\.\d+\.\d+)$/i;
/**
* Get DNS servers.
*
* filepath: resolv config file path. default is '/etc/resolv.conf'.
*/
export function dns(callback: DnsCallback): void;
export function dns(filepath: string, callback: DnsCallback): void;
export function dns(filepathOrCallback: string | DnsCallback, callback?: DnsCallback) {
let filepath: string | undefined;
if (typeof filepathOrCallback === 'function') {
callback = filepathOrCallback;
} else {
filepath = filepathOrCallback;
}
filepath = filepath || DEFAULT_RESOLV_FILE;
fs.readFile(filepath, 'utf8')
.then(content => {
const servers: string[] = [];
content = content || '';
const lines = content.split('\n');
for (const line of lines) {
const m = DNS_SERVER_RE.exec(line.trim());
if (m) {
servers.push(m[1]);
}
}
callback!(null, servers);
})
.catch(err => {
callback!(err);
});
}
/**
* Get all addresses.
*
* interfaceName: interface name, default is 'eth' on linux, 'en' on mac os.
*/
export function address(callback: AddressCallback): void;
export function address(interfaceName: string, callback: AddressCallback): void;
export function address(interfaceNameOrCallback: string | AddressCallback, callback?: AddressCallback) {
let interfaceName: string | undefined;
if (typeof interfaceNameOrCallback === 'function') {
callback = interfaceNameOrCallback;
} else {
interfaceName = interfaceNameOrCallback;
}
const addr: Address = {
ip: ip(interfaceName),
ipv6: ipv6(interfaceName),
mac: undefined,
};
mac(interfaceName || '', (err?: Error | null, mac?: string | null) => {
if (mac) {
addr.mac = mac;
}
callback!(err || null, addr);
});
}

4
node_modules/address/src/index.ts generated vendored Normal file
View File

@@ -0,0 +1,4 @@
import { address } from './address.js';
export * from './address.js';
export default address;

32
node_modules/address/src/promises.ts generated vendored Normal file
View File

@@ -0,0 +1,32 @@
import {
Address, address as getAddress,
mac as getMac,
dns as getDns,
} from './address.js';
export function address(interfaceName?: string) {
return new Promise<Address>((resolve, reject) => {
getAddress(interfaceName || '', (err, address) => {
if (err) return reject(err);
resolve(address);
});
});
}
export function mac(interfaceName?: string) {
return new Promise<string | null>((resolve, reject) => {
getMac(interfaceName || '', (err, address) => {
if (err) return reject(err);
resolve(address || null);
});
});
}
export function dns(filepath?: string) {
return new Promise<string[]>((resolve, reject) => {
getDns(filepath || '', (err, servers) => {
if (err) return reject(err);
resolve(servers || []);
});
});
}