# ip-address 中文文档

规范地址：https://npmcn.com/package/ip-address/

版本：10\.7\.6
npm 元数据更新时间：2026-11-03T16:58:46.491Z
中文译文更新时间：2026-11-05T15:08:26.613Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/ip-address
原文对照：https://npmcn.com/package/ip-address/?lang=original
项目主页：https://github.com/beaugunderson/ip-address#readme
源码仓库：https://github.com/beaugunderson/ip-address

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：369 kB，30 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- Node.js 要求：\>= 12
- 运行依赖：0 个
- 首次发布：2015-05-05T00:32:26.395Z
- 最新版本发布：2026-11-03T16:58:46.090Z
- 近 30 天下载量：400408825（2026-10-05 至 2026-11-03，npm 官方下载统计）
- 已发布版本数：69（近 12 个月 18 个）

## 中文简介

在节点和浏览器中解析IPv4和IPv6 IP地址的库.

## 安装

```sh
npm install ip-address
```

也可以使用：`pnpm add ip-address`、`yarn add ip-address`、`bun add ip-address`

## README

[![CI](https://github.com/beaugunderson/ip-address/actions/workflows/ci.yml/badge.svg)](https://github.com/beaugunderson/ip-address/actions/workflows/ci.yml) [![codecov](https://codecov.io/github/beaugunderson/ip-address/coverage.svg?branch=main)](https://codecov.io/github/beaugunderson/ip-address?branch=main) [![downloads](https://img.shields.io/npm/dm/ip-address.svg)](https://www.npmjs.com/package/ip-address) [![npm](https://img.shields.io/npm/v/ip-address.svg)](https://www.npmjs.com/package/ip-address)

## ip-地址

`ip-address` 是用于验证和操纵JavaScript和TypeScript中的IPv4和IPv6地址的库.

### 安装

```sh
npm install ip-address
```

### 实例

```ts
import { Address4, Address6 } from 'ip-address';

// Validation
Address4.isValid('192.168.1.1');           // true
Address6.isValid('2001:db8::1');           // true
Address6.isValid('not an address');        // false

// Parsing (throws AddressError on invalid input)
const v4 = new Address4('192.168.1.1/24');
const v6 = new Address6('2001:db8::1/64');

// Subnet membership
const host = new Address4('192.168.1.42');
const network = new Address4('192.168.1.0/24');
host.isInSubnet(network);                  // true

// Subnet range
network.startAddress().correctForm();      // '192.168.1.0'
network.endAddress().correctForm();        // '192.168.1.255'

// Strict network-address check (host bits must be zero).
// isValid() accepts CIDRs with host bits set — '192.168.1.5/24' is a valid
// host-with-subnet, but it isn't a network address.
const cidr = new Address4('192.168.1.5/24');
Address4.isValid('192.168.1.5/24');                                // true
cidr.correctForm() === cidr.startAddress().correctForm();          // false

// Address properties
const link = new Address6('fe80::1');
link.isLinkLocal();                        // true
link.isMulticast();                        // false
link.isLoopback();                         // false

new Address4('192.168.1.1').isPrivate();   // true (RFC 1918)
new Address6('fc00::1').isULA();           // true (RFC 4193)

// Numeric and byte representations
v4.bigInt();                               // 3232235777n
v4.toArray();                              // [192, 168, 1, 1]
v6.canonicalForm();                        // '2001:0db8:0000:0000:0000:0000:0000:0001'

// Embedded IPv4 + Teredo
const teredo = new Address6('2001:0:ce49:7601:e866:efff:62c3:fffe');
teredo.inspectTeredo().client4;            // '157.60.0.1'

// Parse host + port from a URL
Address6.fromURL('http://[2001:db8::1]:8080/').port;  // 8080
```

### 特征

-   以 TypeScript 编写, 并附有完整类型定义; 可用于 CommonJS 和 ESM
-   零运行时间依赖关系
-   解析多点平方 IPv4 和 [第4291号公约](https://datatracker.ietf.org/doc/html/rfc4291) IPv6标记,包括子网和区. 这个 `inet_aton` 表单( 表格)`2130706433`, (中文(简体) ), `0x7f000001`, (中文(简体) ), `127.1`)和领先-零octets被设计拒绝——参见: [警卫](https://npmcn.com/package/ip-address/SECURITY.md#classifiers-are-not-an-ssrf-defense)
-   从 URL 解析 IPv6 主机( 和端口) `Address6.fromURL(url)`
-   子网成员检查`isInSubnet`)和范围查询(`startAddress` 编号 : `endAddress`(中文(简体) )
-   特殊财产检查:私人(RFC 1918)/ULA(RFC 4193),回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回
-   解码 [泰雷多语Name](http://en.wikipedia.org/wiki/Teredo_tunneling#IPv6_addressing) 和6至4个隧道信息
-   转换 : 犬形/正形 二进制 二进制 十进制 字节数组 BigInt, `in-addr.arpa` 编号 : `ip6.arpa`
-   在节点.js和浏览器中运行
-   数以千计的测试案例

### 术语

API全程使用的几个名词,如果之前没有深入IPv6的工作,可能会令人困惑:

-   **正确的窗体** ——最短有效代表人数 [RFC 5952 (韩语)](https://datatracker.ietf.org/doc/html/rfc5952): 领先 零 剥离, 最长的零组运行崩溃为 `::`,并小写为十六进制数字(例如:. `2001:db8::1`) (中文(简体) ). 这是大多数软件显示的.
-   **条形** ——代表完全扩大:所有8个组,每组被加到4个正数,没有 `::` 崩溃(例如:. `2001:0db8:0000:0000:0000:0000:0000:0001`) (中文(简体) ). 用于排序和字节精确比较.
-   **子网络** ——以CIDR前缀长度表示的地址的网络部分(例如. `/24` 用于IPv4, `/64` 用于 IPv6 . `startAddress()` 编号 : `endAddress()` 返回子网范围的界限.
-   **区** —— IPv6 范围标识符后附 `%`,用于分解跨接口的链接-本地地址(例如. `fe80::1%eth0`) (中文(简体) ).
-   **v4-in-v6 (英语)** ——将IPv4地址嵌入为IPv6地址后32位的混合标记,例如. `::ffff:192.168.0.1`用于 IPv4 的 IPv6 地址.
-   **泰雷多语Name** – 隧道协议,将 IPv4 端点、端口和旗子编码在 a `2001::/32` IPv6地址. `inspectTeredo()` 解码这些字段.
-   **6至4岁** ——一个将完整的32位IPv4地址嵌入到 16 - 47 位的地道协议 a `2002::/16` IPv6地址,即第二和第三组(`192.0.2.4` 变成 `2002:c000:204::`) (中文(简体) ). `inspect6to4()` 解码嵌入式v4地址.

### API 密码

**地址4** ——代表IPv4地址

**构造器**

-   `new Address4(address: string): Address4`

**静态方法**

-   `static isValid(address: string): boolean` ——如果给定的字符串是一个有效的IPv4地址(带有可选的 CIDR 子网),则返回真实,否则会作假. 允许子网部分的主机位(如. `192.168.1.5/24` 有效);对于严格的网络地址验证比较 `correctForm()` 改为 `startAddress().correctForm()`,或使用 `networkForm()`。 。 。 . [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L62)
-   `static fromAddressAndMask(address: string, mask: string): Address4` - 构造一个 `Address4` 来自地址和一个点-小数子网口罩,作为单独的字符串(例如由节点返回) `os.networkInterfaces()`) (中文(简体) ). 掷出 `AddressError` 如果口罩不相接(例如:. `255.0.255.0`) (中文(简体) ). [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L119)
-   `static fromAddressAndWildcardMask(address: string, wildcardMask: string): Address4` - 构造一个 `Address4` 从地址和Cisco风格的通配符口罩中取出,作为单独的字符串(例如:. `0.0.0.255` (单位:千美元) `/24`) (中文(简体) ). 通配符口罩是子网口罩的位元反相. 掷出 `AddressError` 如果口罩不相接(例如:. `0.255.0.255`) (中文(简体) ). [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L133)
-   `static fromWildcard(input: string): Address4` - 构造一个 `Address4` 从带有后缀的通配符模式 `*` oc. 后缀通配符数决定前缀长度:每张 `*` 代表8位数。 仅支持后端的全奥氏通配符. 部分octet通配符(例如:. `192.168.0.1*`)和内置通配符(如. `192.*.0.1`投掷 `AddressError`。 。 。 . [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L154)
-   `static fromHex(hex: string): Address4` ——将一六重字符串转换为IPv4地址对象. 接受可选的 8 六进制数字 `:` 分离器(例如:. `'7f000001'` 或者说 `'7f:00:00:01'`) (中文(简体) ). 掷出 `AddressError` 用于其他长度或非hex字符. [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L189)
-   `static fromInteger(integer: number): Address4` ——将整数转换为IPv4地址对象. 整数必须是该范围内的非负式安全整数 `[0, 2**32 - 1]`; 否则 `AddressError` 被抛出. [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L212)
-   `static fromArpa(arpaFormAddress: string): Address4` ——从addr.arpa表格返回地址: 四个octets倒置,是否带有 `.in-addr.arpa` 后缀和根点,无论如何。 掷出 `AddressError` 除非反转的标签构成有效的IPv4地址,所以 `fromArpa(x.reverseForm())` 圆通倒转Form. [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L231)
-   `static fromBigInt(bigInt: bigint): Address4` ——将 BigInt 转换为 v4 地址对象。 值必须在范围内 `[0, 2**32 - 1]`; 否则 `AddressError` 被抛出. [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L422)
-   `static fromByteArray(bytes: number[]): Address4` - 将字节数组转换为地址4对象。 掷出 `AddressError` 除非给出精确的4个整数从0到255。 签名的字节被拒绝, 因此这与 `Address6.fromByteArray`这两个合同在下一个主要版本中与这种更为严格的形式一致。 从节点转换 `Buffer`,传播: `Address4.fromByteArray([...buf])`。 。 。 . [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L440)
-   `static fromUnsignedByteArray(bytes: number[]): Address4` - 将一个未签名的字节数组转换为地址4对象。 掷出 `AddressError` 除非给出精确的 4 字节,并在解析结果地址时拒绝 0 到 255 以外的值。 从节点转换 `Buffer`,传播: `Address4.fromUnsignedByteArray([...buf])`。 。 。 . [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L456)

**实例方法**

-   `parse(address: string): string[]` ——将 IPv4 地址字符串分解到其四个octet组中,并将结果存储在 `this.parsedAddress`。由构造器自动调用;通常不需要直接调用。 掷出 `AddressError` 如果输入不是一个有效的 IPv4 地址. [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L79)
-   `correctForm(): string` ——以正确的形式返回地址:octets与 `.` 和任何已剥去的正0(例如. `192.168.1.1`) (中文(简体) ). 对于IPv4来说,这符合Cononical potted-十进制代表. [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L100)
-   `toHex(): string` - 将 IPv4 地址对象转换为十六进制字符串 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L254)
-   `toArray(): number[]` ——将 IPv4 地址对象转换为数组字节. 要得到节点J `Buffer`,将结果包起来: `Buffer.from(address.toArray())`。 。 。 . [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L264)
-   `toGroup6(): string` - 将 IPv4 地址对象转换为 IPv6 地址组 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L272)
-   `bigInt(): bigint` - 将地址作为 `bigint` [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L291)
-   `startAddress(): Address4` ——该地址子网给出范围内的第一个地址. 常被称作"网络地址". [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L308)
-   `startAddressExclusive(): Address4` ——该地址子网给出范围的首个主机地址 ie 网络地址后的第一个地址 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L317)
-   `offset(n: number | bigint): Address4` - 返回地址 `n` 在此地址之后( 或在此之前, 何时) `n` 保留此地址的子网口罩。 掷出 `AddressError` 当结果位于 IPv4 地址空间之外,或者 `n` 不是一个整数. [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L332)
-   `nextNetwork(): Address4` ——返回这个地址的网络: endadress后地址,带有相同的子网口罩. 掷出 `AddressError` 当此网络是地址空间中最后一个时. [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L346)
-   `endAddress(): Address4` ——该地址所给出范围内的最后一个地址"子网"常被称作"广播" [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L369)
-   `endAddressExclusive(): Address4` ——本地址子网给出范围内最后一个主机地址为广播地址前最后一个地址 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L378)
-   `subnetMaskAddress(): Address4` ——子网口罩的点-十进制形式,例如. `255.255.240.0` (单位:千美元) `/20`返回 a `Address4`; 调用 `.correctForm()` 用于字符串. [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L388)
-   `wildcardMask(): Address4` ——思科式通配卡口罩等. `0.0.0.255` (单位:千美元) `/24`。这是比特反向的 `subnetMaskAddress()`返回 a `Address4`; 调用 `.correctForm()` 用于字符串. [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L400)
-   `networkForm(): string` —— CIDR字符串形式的网络地址,例如. `192.168.1.0/24` 页:1 `192.168.1.5/24`。对于没有明确子网的地址,前缀是 `/32`,比如说. `networkForm()` 打开 `192.168.1.5` 返回时 `192.168.1.5/32`。 。 。 . [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L412)
-   `mask(mask?: number): string` — 返回地址的第一个 n 位元, 默认为子网掩码 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L470)
-   `getBitsBase2(start: number, end: number): string` — 返回给定范围内的比特作为基数-2字符串 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L482)
-   `reverseForm(options?: ReverseFormOptions): string` 返回地址的倒转式内加法形式,例如:. `42.2.0.192.in-addr.arpa.` 页:1 `192.0.2.42`。 。 。 . [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L493)
-   `isMulticast(): boolean` —— 如果给定地址是多播地址, 返回为真 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L531)
-   `isPrivate(): boolean` ——如果地址位于其中之一,返回真实 [RFC 1918 (英语)](https://datatracker.ietf.org/doc/html/rfc1918) 私人地址范围( e)`10.0.0.0/8`, (中文(简体) ), `172.16.0.0/12`, (中文(简体) ), `192.168.0.0/16`) (中文(简体) ). [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L539)
-   `isLoopback(): boolean` —— 如果地址位于回转范围, 返回真实值 `127.0.0.0/8` (单位:千美元)[RFC 1122 (韩语)](https://datatracker.ietf.org/doc/html/rfc1122)) (中文(简体) ). [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L547)
-   `isLinkLocal(): boolean` —— 如果地址位于链接- 本地范围内, 返回为真 `169.254.0.0/16` (单位:千美元)[RFC 3927 (法语)](https://datatracker.ietf.org/doc/html/rfc3927)) (中文(简体) ). [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L555)
-   `isUnspecified(): boolean` —— 如果地址是未指明地址, 返回为真 `0.0.0.0`。 。 。 . [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L563)
-   `isBroadcast(): boolean` ——如果地址是有限的广播地址,则返回真实情况 `255.255.255.255` (单位:千美元)[RFC 919 (英语)](https://datatracker.ietf.org/doc/html/rfc919)) (中文(简体) ). [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L571)
-   `isCGNAT(): boolean` - 如果地址位于载体级NAT范围内,则返回真实性 `100.64.0.0/10` (单位:千美元)[RFC 6598 (法语)](https://datatracker.ietf.org/doc/html/rfc6598)) (中文(简体) ). [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L579)
-   `isDocumentation(): boolean` — 如果地址位于文件范围之一, 返回为真实 `192.0.2.0/24`, (中文(简体) ), `198.51.100.0/24`,或 `203.0.113.0/24` (单位:千美元)[RFC 5737 (英语)](https://datatracker.ietf.org/doc/html/rfc5737)) (中文(简体) ). [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L588)
-   `isBenchmarking(): boolean` ——如果地址在基准范围内,返回真实性 `198.18.0.0/15` (单位:千美元)[RFC 2544 (法语)](https://datatracker.ietf.org/doc/html/rfc2544)) (中文(简体) ). [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L596)
-   `isReserved(): boolean` —— 如果地址在保留范围内, 返回为真 `240.0.0.0/4` (单位:千美元)[RFC 1112 (英语)](https://datatracker.ietf.org/doc/html/rfc1112)包括有限的广播地址. [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L605)
-   `isGlobal(): boolean` ——如果地址是全球可达到的,则返回真实:不是多播,也不是在任何块中 [IANA IPv4 特殊目的地址登记](https://www.iana.org/assignments/iana-ipv4-special-registry/) 标记为无法在全球达到。 这涵盖了个人分类名称(私人、回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回回 `0.0.0.0/8` 和 IETF 协议任务 `192.0.0.0/24`。这是不能将请求送到内部或特殊用途目的地的单一前提;见Security.md. [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L620)
-   `binaryZeroPad(): string` - 返回地址的零加法基-2字符串表示 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L628)
-   `groupForV6(): string` ——组合一个IPv4地址,以收录在IPv6地址的末尾. 返回 HTML 片段: 地址的每半个被包裹在一个 `<span>` 搭载组级 地址检查员UI徘徊。 地址内容是 HTML- 逃避的; 任何你围绕它所定义的东西都是你的责任 . [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L644)

**属性**

-   `address: string` —— 说 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L14)
-   `addressMinusSuffix: string` —— 说 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L15)
-   `groups: number` —— 说 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L16)
-   `parsedAddress: string[]` —— 说 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L17)
-   `parsedSubnet: string` —— 说 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L18)
-   `subnet: string` —— 说 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L19)
-   `subnetMask: number` —— 说 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L20)
-   `v4: boolean` —— 说 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L21)
-   `isCorrect: () => boolean` ——如果地址正确、不正确,返回真实 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L108)
-   `isInSubnet: (address: Address4 | Address6) => boolean` —— 如果给定地址位于当前地址的子网中, 返回为真 。 一个 `Address6` 从来没有在子网中 `Address4`; 转换为 `to4()` 或者说 `Address6.fromAddress4()` 以比较各个家庭. [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L513)
-   `isHostInSubnet: (address: Address4 | Address6) => boolean` ——如果此地址的主机位落在给定子网内,则返回真实性,忽略了此地址自己的子网掩码. 更喜欢这个 `isInSubnet` 当对单个地址进行分类时,所以答案不会随着CIDR后缀而改变,呼叫者碰巧会写出——特别是当地址来自不可信输入,结果背出一个信任边界的决定时. 一个 `Address6` 从来没有在子网中 `Address4`; 转换为 `to4()` 或者说 `Address6.fromAddress4()` 以比较各个家庭. [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv4.ts#L525)

**地址6** - 代表IPv6地址

**构造器**

-   `new Address6(address: string, optionalGroups?: number): Address6`

**静态方法**

-   `static isValid(address: string): boolean` ——如果给定的字符串是一个有效的IPv6地址(带有可选的 CIDR 子网和区标识符),则返回真实,否则是虚假的. 允许子网部分的主机位(如. `2001:db8::1/32` 有效);对于严格的网络地址验证比较 `correctForm()` 改为 `startAddress().correctForm()`,或使用 `networkForm()`。 。 。 . [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L182)
-   `static fromBigInt(bigInt: bigint): Address6` — 将 BigInt 转换为 v6 地址对象 。 值必须在范围内 `[0, 2**128 - 1]`; 否则 `AddressError` 被抛出. [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L203)
-   `static fromURL(url: string): { error: string; address: null; port: null } | { error?: undefined; address: Address6; port: number | null }` ——将一个URL(带有可选的括号内主机和端口)分析到地址和端口. 返回( 返回) `{ address, port }` 成功时或 `{ error, address: null, port: null }` 如果无法解析 URL。 端口作为数字返回(或 `null` (如果缺席或超出范围). [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L228)
-   `static fromAddressAndMask(address: string, mask: string): Address6` - 构造一个 `Address6` 从地址和hex 子网口罩中指定为单独的字符串(例如由节点返回) `os.networkInterfaces()`) (中文(简体) ). 掷出 `AddressError` 如果口罩不相接(例如:. `ffff::ffff`) (中文(简体) ). [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L295)
-   `static fromAddressAndWildcardMask(address: string, wildcardMask: string): Address6` - 构造一个 `Address6` 从地址和Cisco风格的通配符口罩中取出,作为单独的字符串(例如:. `::ffff:ffff:ffff:ffff` (单位:千美元) `/64`) (中文(简体) ). 通配符口罩是子网口罩的位元反相. 掷出 `AddressError` 如果面具是非相接的. [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L309)
-   `static fromWildcard(input: string): Address6` - 构造一个 `Address6` 从带有后缀的通配符模式 `*` 组合。 后缀通配符数决定前缀长度:每张 `*` 代表16个比特. `::` 在评价后端通配符之前,扩展为零组(不是通配符)。 只支持后端的整组通配符 。 部分组合通配符(例如:. `2001:db8::0*`)和内置通配符(如. `*::1`投掷 `AddressError`。 。 。 . [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L331)
-   `static fromAddress4(address: string): Address6` —— 创建一个 IPv6 给定的地址 IPv4 地址 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L392)
-   `static fromArpa(arpaFormAddress: string): Address6` 从ip6.arpa表格中返回地址。 一个完整的32尼伯名称给出了/128地址;一个更短的名字,用于授权倒行区,让它覆盖的网络,一个子网口罩每尼伯有四个比特,所以 `fromArpa(x.reverseForm())` 任意前缀的回转格式. [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L412)
-   `static fromAddress4Nat64(address: string, prefix?: string): Address6` ——利用由 NAT64 IPv6 定义的编码将 IPv4 地址嵌入到 NAT64 IPv6 地址中 [RFC 6052 (法语)](https://datatracker.ietf.org/doc/html/rfc6052)。默认前缀是众所周知的前缀 `64:ff9b::/96`. 前缀的长度必须是32,40,48,56,64或96个;对于比64短的前缀,IPv4 octets被围绕保留位号64–71来划分. [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L1122)
-   `static fromByteArray(bytes: number[]): Address6` ——将字节数组转换为地址6对象。 接受未签名的字节(0至255)或已签名的字节(-128至127,作为 `Int8Array` 或爪哇语 `byte[]` 将签名的值折叠到其未签名的等值。 掷出 `AddressError` 除非给出精确的16个整数从-128到-255。 从节点转换 `Buffer`,传播: `Address6.fromByteArray([...buf])`。 。 。 . [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L1237)
-   `static fromUnsignedByteArray(bytes: number[]): Address6` - 将一个未签名的字节数组转换为地址6对象。 掷出 `AddressError` 除非给出精确的16个整数从0到255。 从节点转换 `Buffer`,传播: `Address6.fromUnsignedByteArray([...buf])`。 。 。 . [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L1254)

**实例方法**

-   `microsoftTranscription(): string` ——归还微软UNC地址的抄本 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L437)
-   `mask(mask?: number): string` ——返回地址的第一个 n 位元,默认为子网掩码 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L446)
-   `possibleSubnets(subnetSize?: number): string` ——返回地址中某个大小的可能子网的数目 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L456)
-   `startAddress(): Address6` ——此地址"子网"给出范围内的第一个地址常被称作"网络地址". [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L481)
-   `startAddressExclusive(): Address6` ——该地址子网给出范围的首个主机地址 ie 网络地址后的第一个地址 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L490)
-   `endAddress(): Address6` ——该地址子网给出范围的最后一个地址. IPv6没有广播地址,因此这是一个普通的可分配地址(在一个64位的界面识别子网中,它位于保留子网的Anycast块内,即 [RFC 2526 (韩语)](https://datatracker.ietf.org/doc/html/rfc2526)) (中文(简体) ). [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L510)
-   `endAddressExclusive(): Address6` - 地址在地址前的一个 这是IPv6方法的IPv6对应版本,它跳过广播地址;IPv6没有广播,因此它完全降下一个地址,不模拟128个保留的子网-anycast标识符 [RFC 2526 (韩语)](https://datatracker.ietf.org/doc/html/rfc2526)。 。 。 . [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L521)
-   `offset(n: number | bigint): Address6` - 返回地址 `n` 在此地址之后( 或在此之前, 何时) `n` 保留此地址的子网口罩。 掷出 `AddressError` 当结果位于 IPv6 地址空间之外时,或者 `n` 不是一个整数. [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L536)
-   `nextNetwork(): Address6` ——返回这个地址的网络: endadress后地址,带有相同的子网口罩. 掷出 `AddressError` 当此网络是地址空间中最后一个时. [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L550)
-   `subnetMaskAddress(): Address6` ——子网口罩的六分法形式,例如. `ffff:ffff:ffff:ffff::` (单位:千美元) `/64`返回 a `Address6`; 调用 `.correctForm()` 用于字符串. [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L565)
-   `wildcardMask(): Address6` ——思科式通配卡口罩等. `::ffff:ffff:ffff:ffff` (单位:千美元) `/64`。这是比特反向的 `subnetMaskAddress()`返回 a `Address6`; 调用 `.correctForm()` 用于字符串. [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L577)
-   `networkForm(): string` —— CIDR字符串形式的网络地址,例如. `2001:db8::/32` 页:1 `2001:db8::1/32`。对于没有明确子网的地址,前缀是 `/128`,比如说. `networkForm()` 打开 `2001:db8::1` 返回时 `2001:db8::1/128`。 。 。 . [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L590)
-   `getScope(): string` ——归还地址范围. 4- 位范围字段( E)[RFC 4291 第2.7节](https://datatracker.ietf.org/doc/html/rfc4291#section-2.7))只定义为多播地址;对于独播地址,范围取自每集的地址类型 [RFC 4007 第6节](https://datatracker.ietf.org/doc/html/rfc4007#section-6)。 。 。 . [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L602)
-   `getType(): string` ——返回地址类型 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L629)
-   `getBits(start: number, end: number): bigint` —— 返回给定范围内的位点为 BigInt [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L644)
-   `getBitsBase2(start: number, end: number): string` ——返回给定范围内的比特作为基数-2字符串 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L652)
-   `getBitsBase16(start: number, end: number): string` ——返回给定范围内的比特作为基数-16字符串 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L660)
-   `getBitsPastSubnet(): string` ——返回通过子网口罩长度设置的位数 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L676)
-   `reverseForm(options?: ReverseFormOptions): string` 返回地址倒转的 ip6. arpa 形式 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L686)
-   `correctForm(): string` - 按正确形式返回地址,按 [RFC 5952 (韩语)](https://datatracker.ietf.org/doc/html/rfc5952): 领先 零 剥离, 最长的零组运行崩溃为 `::`,并小写为十六进制数字(例如:. `2001:db8::1`) (中文(简体) ). 这是推荐的显示表 . [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L721)
-   `binaryZeroPad(): string` ——返回地址的零加法基-2字符串表示 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L783)
-   `parse4in6(address: string): string` ——解析一v4-in-v6字符串(例如. `::ffff:192.168.0.1`)通过将后继的IPv4地址取入 `this.address4` 编号 : `this.parsedAddress4` 并返回地址,将v4部分转换为两个v6组。 内部使用 `parse()`。 。 。 . [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L797)
-   `parse(address: string): string[]` ——将 IPv6 地址字符串分解到其8个十六进制组(扩展任意) `::` 消除和任何后继v4-in-v6部分,并将结果存储在 `this.parsedAddress`。由构造器自动调用;通常不需要直接调用。 掷出 `AddressError` 如果输入格式不当. [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L854)
-   `canonicalForm(): string` 返回地址的条形(完全扩大)形式:所有8个组,每个组加到4个正数,没有 `::` 崩溃(例如:. `2001:0db8:0000:0000:0000:0000:0000:0001`) (中文(简体) ). 用于排序和字节精确比较. [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L937)
-   `decimal(): string` ——返回地址的小数形式 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L945)
-   `bigInt(): bigint` - 以 BigInt 身份返回地址 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L953)
-   `to4(): Address4` ——将这个地址的最后两组作为IPv4地址字符串返回. 如果这个地址带有一个CIDR前缀,覆盖后端的32位(即:. `subnetMask >= 96`),结果 `Address4` 继承相应的 v4 前缀 (`subnetMask - 96`; 否则默认为 `/32`。 。 。 . [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L968)
-   `to4in6(): string` ——返回地址的v4-in-v6形式 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L992)
-   `inspectTeredo(): TeredoProperties` ——解码此地址所嵌入的特雷多地道道场. 返回 Teredo 前缀,服务器 IPv4,客户端 IPv4,生旗位,锥-NAT 旗,UDP 端口,和微软格式旗分解(保留,通用/本地,组/个人,非ce). 仅对地址有意义 `2001::/32`。 。 。 . [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L1013)
-   `inspect6to4(): SixToFourProperties` ——解码此地址所嵌入的6to4地道通场. 返回 6to4 前缀和嵌入式 IPv4 网关地址 。 仅对地址有意义 `2002::/16`。 。 。 . [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L1076)
-   `to6to4(): Address6 | null` ——从 v6 v4inv6 地址返回 v6 6to4 地址 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L1096)
-   `toAddress4Nat64(prefix?: string): Address4 | null` – 从 NAT64 IPv6 地址中提取嵌入式IPv4 地址,使用编码由 [RFC 6052 (法语)](https://datatracker.ietf.org/doc/html/rfc6052)。默认前缀是众所周知的前缀 `64:ff9b::/96`. 回归 `null` 如果该地址未包含在给定的前缀中. [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L1165)
-   `toByteArray(): number[]` 返回字节数组。 要得到节点J `Buffer`,将结果包起来: `Buffer.from(address.toByteArray())`。 。 。 . [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L1200)
-   `toUnsignedByteArray(): number[]` 返回一个未签名的字节数组 。 要得到节点J `Buffer`,将结果包起来: `Buffer.from(address.toUnsignedByteArray())`。 。 。 . [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L1219)
-   `isCanonical(): boolean` ——如果地址为犬形,则返回真实,否则是虚假的 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L1301)
-   `isLinkLocal(): boolean` —— 如果地址是链接- 本地独播地址, 返回真实性 `fe80::/10` (单位:千美元)[RFC 4291 第2.4节](https://datatracker.ietf.org/doc/html/rfc4291#section-2.4))或一个IPv4-mapped / NAT64地址,其嵌入式IPv4地址为链接-本地(`169.254.0.0/16`,比如说. `::ffff:169.254.169.254`),否则是虚假的. [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L1312)
-   `isMulticast(): boolean` ——如果地址是多播地址,则返回真实,否则是虚假的 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L1325)
-   `is4(): boolean` ——如果地址是用v4-in-v6dotted-quad注解(例如. `::ffff:127.0.0.1`),否则是虚假的. 这是一个标记级别旗帜,没有反映地址位是否位于 IPv4- mapped ()`::ffff:0:0/96`)子网——对此参见:Mapped4. [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L1342)
-   `isMapped4(): boolean` —— 如果地址是 IPv4- mapped IPv6 地址, 返回真实性 `::ffff:0:0/96` (单位:千美元)[RFC 4291 第2.5.5.2节](https://datatracker.ietf.org/doc/html/rfc4291#section-2.5.5.2)),否则是虚假的. 与s4不同,这检查了基本的地址比特,而不是文字上的注解,所以 `::ffff:127.0.0.1` 财务报告和审定财务报表 `::ffff:7f00:1` 都回归真实. [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L1354)
-   `embeddedIPv4(): Address4 | null` ——如果该地址嵌入了routable IPv4地址——即是IPv4-mapped ()`::ffff:0:0/96`)或坐入NAT64名出名的前缀中(出自:`64:ff9b::/96`, (中文(简体) ), [RFC 6052 (法语)](https://datatracker.ietf.org/doc/html/rfc6052)) ——将嵌入式地址作为地址返回;否则返回无效。 特别财产检查`isLoopback`, (中文(简体) ), `isLinkLocal`, (中文(简体) ), `isMulticast`, (中文(简体) ), `isUnspecified`, (中文(简体) ), `isPrivate`, (中文(简体) ), `isCGNAT`, (中文(简体) ), `isBroadcast`) 将这个调用为先, 并代表到嵌入式地址4 当存在时, 所以一个字形如 `::ffff:127.0.0.1` 按其实际达到的(loopback)而不是其IPv6包装器(Which)分类 `getType()` 页:1 不论何种情况,这都很重要,因为只要核查回溯了一项信任范围的决定(例如,安保部门监督框架允许/拒绝过滤):没有正常化, `::ffff:10.0.0.1`, (中文(简体) ), `::ffff:169.254.169.254`, (中文(简体) ), `64:ff9b::7f00:1`等都读作非内部. [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L1375)
-   `isTeredo(): boolean` ——如果地址是Teredo地址,则返回真实,否则是虚假的 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L1387)
-   `is6to4(): boolean` - 如果地址是 6to4 地址,则返回为真,否则是假的 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L1395)
-   `isLoopback(): boolean` ——如果地址是回回地址,则返回真实,否则是虚假的 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L1403)
-   `isULA(): boolean` — 如果地址是本地地址, 返回真实性 `fc00::/7` (单位:千美元)[第4193号条例](https://datatracker.ietf.org/doc/html/rfc4193). ULAs 为IPv6等同于IPv4 [RFC 1918 (英语)](https://datatracker.ietf.org/doc/html/rfc1918) 个人地址. [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L1416)
-   `isPrivate(): boolean` —— 如果地址是私人地址, 返回真实地址, 即本地地址 `fc00::/7` (单位:千美元)[第4193号条例](https://datatracker.ietf.org/doc/html/rfc4193)),NAT64本地使用范围的地址 `64:ff9b:1::/48` (单位:千美元)[RFC 8215 (中文(简体) )](https://datatracker.ietf.org/doc/html/rfc8215)),或一个IPv4-mapped / NAT64的知名地址,其嵌入式IPv4地址位于其中之一 [RFC 1918 (英语)](https://datatracker.ietf.org/doc/html/rfc1918) 私人范围(例如:. `::ffff:10.0.0.1`) (中文(简体) ). 这是地址4的 IPv6 对应器。 当您需要捕捉绘制的 RFC 1918 地址以及本地的 ULA 时, 使用它代替 isULA 。 本地用途 NAT64 范围是整个私有的, 而不是其嵌入式IPv4 地址: 操作员可以将 RFC 6052 长度的前缀刻出 `64:ff9b:1::/48`,因此同一比特在不同的部署下解码到不同的IPv4地址,没有单一的解码是正确的. 使用Adress4Nat64与部署的前缀来解码一. [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L1438)
-   `isCGNAT(): boolean` — 如果地址是 IPv4- mapped / NAT64 地址, 其嵌入式 IPv4 地址位于 载体级 NAT 范围内, 则返回真实 `100.64.0.0/10` (单位:千美元)[RFC 6598 (法语)](https://datatracker.ietf.org/doc/html/rfc6598)),否则是虚假的. 没有原生的IPv6 CGNAT范围,因此这只为嵌入式IPv4地址(例如. `::ffff:100.64.0.1`) (中文(简体) ). [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L1455)
-   `isBroadcast(): boolean` —— 如果地址是 IPv4- mapped / NAT64 地址, 其嵌入式 IPv4 地址是 有限广播地址, 则返回真实地址 `255.255.255.255` (单位:千美元)[RFC 919 (英语)](https://datatracker.ietf.org/doc/html/rfc919)),否则是虚假的. 没有IPv6的广播,因此这只为嵌入式IPv4地址(例如. `::ffff:255.255.255.255`) (中文(简体) ). [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L1472)
-   `isUnspecified(): boolean` —— 如果地址是未指明地址, 返回为真 `::`。 。 。 . [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L1485)
-   `isDocumentation(): boolean` — 如果地址位于文档前缀中, 返回真实性 `2001:db8::/32` (单位:千美元)[第3849号公约](https://datatracker.ietf.org/doc/html/rfc3849)) (中文(简体) ). [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L1498)
-   `isBenchmarking(): boolean` ——如果地址在基准范围内,返回真实性 `2001:2::/48` (单位:千美元)[RFC 5180 (法语)](https://datatracker.ietf.org/doc/html/rfc5180))或是一个IPv4-mapped / NAT64地址,其嵌入式IPv4地址位于 `198.18.0.0/15`,假的别. [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L1509)
-   `isGlobal(): boolean` ——如果地址可以在全球范围内达到,则返回真实:在全球独播分配范围内 `2000::/3` (唯一的范围为: [IANA IPv6 地址空间登记](https://www.iana.org/assignments/ipv6-address-space/) 指定用于全局独播; 其他所有都保留, ULA, 链接- 本地, 或多播) 而不是在任何块中 [IANA IPv6 特殊用途地址登记处](https://www.iana.org/assignments/iana-ipv6-special-registry/) 标记为无法在全球达到。 其嵌入式IPv4地址的 IPv4- mapped 或 NAT64 知名地址解答, 所以 `::ffff:10.0.0.1` 财务报告和审定财务报表 `64:ff9b::7f00:1` 不是全球性的。 泰雷多( 泰雷多 )`2001::/32`)和6至4 (中文(简体) )`2002::/16`)也不是全球性的:登记册将它们列为无源/无源数据,给一个包需要中继。 这涵盖了各个分类者名称和它们没有的块: 仅丢弃的前缀 `100::/64`,在 `2001::/23`, 被破坏的站点 - 本地 `fec0::/10` 和 IPv4 兼容 `::/96` 区域,以及诸如 `4000::/3`在请求不能到达内部或特殊目的目的地的情况下,使用该程序是单一的前提;见Security.md. [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L1538)
-   `href(optionalPort?: string | number): string` ——将地址作为HTTP URL与主机括号一起返回,例如. `http://[2001:db8::1]/`如果 `optionalPort` 但须附上,例如:. `http://[2001:db8::1]:8080/`。 。 。 . [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L1557)
-   `link(options?: { className?: string; prefix?: string; v4?: boolean }): string` 返回一个 HTML `<a>` 其内容 `href` 在 URL 散列片段中编码地址( 默认前缀) `/#address=`) (中文(简体) ). 用于地址检查器UI的页面间连接 . [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L1575)
-   `group(): string` 一组地址 返回 HTML 片段: 每个组被包裹在一个 `<span>` 搭载组级 地址检查员UI徘徊。 地址内容是 HTML- 逃避的; 任何你围绕它所定义的东西都是你的责任 . [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L1620)
-   `regularExpressionString(substringSearch?: boolean): string` ——生成一个正则表达式字符串,用于查找或验证此地址的所有变体 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L1672)
-   `regularExpression(substringSearch?: boolean): RegExp` ——生成一个正则表达式,可用于查找或验证此地址的所有变体. [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L1726)

**属性**

-   `address4: Address4` —— 说 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L97)
-   `address: string` —— 说 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L98)
-   `addressMinusSuffix: string` —— 说 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L99)
-   `elidedGroups: number` —— 说 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L100)
-   `elisionBegin: number` —— 说 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L101)
-   `elisionEnd: number` —— 说 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L102)
-   `groups: number` —— 说 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L103)
-   `parsedAddress4: string` —— 说 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L104)
-   `parsedAddress: string[]` —— 说 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L105)
-   `parsedSubnet: string` —— 说 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L106)
-   `subnet: string` —— 说 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L107)
-   `subnetMask: number` —— 说 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L108)
-   `v4: boolean` —— 说 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L109)
-   `zone: string` —— 说 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L110)
-   `isInSubnet: (address: Address4 | Address6) => boolean` —— 如果给定地址位于当前地址的子网中, 返回为真 。 一个 `Address4` 从来没有在子网中 `Address6`; 转换为 `Address6.fromAddress4()` 或者说 `to4()` 以比较各个家庭. [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L1277)
-   `isHostInSubnet: (address: Address4 | Address6) => boolean` ——如果此地址的主机位落在给定子网内,则返回真实性,忽略了此地址自己的子网掩码. 更喜欢这个 `isInSubnet` 当对单个地址进行分类时,所以答案不会随着CIDR后缀而改变,呼叫者碰巧会写出——特别是当地址来自不可信输入,结果背出一个信任边界的决定时. 一个 `Address4` 从来没有在子网中 `Address6`; 转换为 `Address6.fromAddress4()` 或者说 `to4()` 以比较各个家庭. [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L1289)
-   `isCorrect: () => boolean` ——如果地址正确、不正确,返回真实 [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/ipv6.ts#L1295)

**地址错误**

**构造器**

-   `new AddressError(message: string, parseMessage?: string): AddressError`

**属性**

-   `parseMessage: string` - 与未能解析内容的部分有关的违法地址 `<span class="parse-error">`,比如说. `2001:db8<span class="parse-error">:::</span>1`。仅显示从可指向特定子字符串的剖析路径所抛出的错误。 这是一个 HTML 片段,用于地址检查器 UI 。 地址内容为 HTML- 逃逸, 所以可以安全地插入 as- is ; 把它当作标记而非纯文本消息, 并使用 `message` 对于任何做成文本. [曲线](https://github.com/beaugunderson/ip-address/blob/main/src/address-error.ts#L13)

### 警卫

脆弱性经历 [GitHub的私人脆弱性报告](https://github.com/beaugunderson/ip-address/security/advisories/new)· ; [警卫](https://npmcn.com/package/ip-address/SECURITY.md) 拥有范围和预期 确认的问题得到解决,释放,和大众 [咨询](https://github.com/beaugunderson/ip-address/security/advisories) 与CVE,而不是一个安静的补丁.

发行版由CI通过npm信任的出版建立并出版. 从10.2.1起,每个版本都附有证明,将焦油球与建造焦油球的承诺和工作流程挂钩。 检查一下 `npm audit signatures`。 。 。 .

如果您使用地址属性检查作为安全控制,请读取 [安全事务科](https://npmcn.com/package/ip-address/SECURITY.md#classifiers-are-not-an-ssrf-defense) 先说. `isPrivate()`, (中文(简体) ), `isLoopback()`, (中文(简体) ), `isInSubnet()` 他们的兄弟姐妹们将一个已经解析过的地址分类,这使得他们成为了SSF守卫的一层而不是整个层. 确定内部地址的主机名, 检查后更改的 DNS 记录, 或重定向 都会通过一个仅建在它们上的守卫 。 在这层,用 `isGlobal()` iANA特殊用途登记册标记为无法在全球达到的区块,包括没有自己分类的区块.

### 用于

`ip-address` 每周下载8 600万次,主要通过节点代理/代理生态系统。 依赖链穿过少数广泛使用的包:

-   [**袜子**](https://github.com/JoshGlazebrook/socks) (~53M周刊) — SOCKS4/5 节点客户端; 取决于 `ip-address` 直接说 单一最大下载源.
-   [**袜子代用剂**](https://github.com/TooTallNate/proxy-agents/tree/main/packages/socks-proxy-agent) (~55M周刊)- `http.Agent` 用于 SOCKS 代理; 取决于 `socks`几乎每个尊重 `HTTPS_PROXY`。 。 。 .
-   [**无**](https://github.com/npm/cli) 财务报告和审定财务报表 [**小时**](https://github.com/pnpm/pnpm) - 两个包 `socks-proxy-agent` 通过其 HTTP 获取堆栈( Name`make-fetch-happen` → `@npmcli/agent`),因此地球上的每一个节点安装都拉入 `ip-address` 作为过渡性依赖.
-   [**傀儡**](https://github.com/puppeteer/puppeteer) —— 说 `@puppeteer/browsers` 用途 `proxy-agent` 用于浏览器-二进制下载,其中的路径 `socks-proxy-agent` → `socks` → `ip-address`。 。 。 .
-   [**代理代理代理人**](https://github.com/TooTallNate/proxy-agents/tree/main/packages/proxy-agent) (~28M周刊)和 [**和平代用剂**](https://github.com/TooTallNate/proxy-agents/tree/main/packages/pac-proxy-agent) (~27M周刊)——自动检测代理代理代理(HTTP/HTTPS/SCKS/PAC)被广泛用于刮取,无头浏览器和CI工具.
-   [**缓存**](https://github.com/npm/cacache) (~40M周刊)——npm内容可处理缓存;拉入同取堆栈.

在代理链之外, `ip-address` 被Juniper Networks的 Contrail, Ably 的代理程序执行, Rackspace 的序列化框架, IPFS, 以及 IPFS 和 IPFS 所使用 [SwitchyOmega (英语)](https://github.com/FelisCatus/SwitchyOmega) 克罗梅扩展等多种.

## 常见问题

### ip-address 是什么？

在节点和浏览器中解析IPv4和IPv6 IP地址的库\.

### 如何安装 ip-address？

在项目目录运行 npm install ip-address，或使用 pnpm add / yarn add / bun add。

### ip-address 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### ip-address 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### ip-address 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>= 12。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### ip-address 可以商用吗？

ip-address 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### ip-address 的下载量有多少？

根据 npm 官方下载统计，ip-address 在 2026/10/05 – 2026/11/03 这 30 天内被下载 400,408,825 次，日均约 13,346,961 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### ip-address 还在维护吗？

最新版本 10\.7\.6 发布于 2026/11/04（2 天前）；至今共发布 69 个版本，其中过去 12 个月发布了 18 个；首次发布于 2015/05/05。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

