净参数
分析并操纵 IPv4 和 IPv6 网络地址
安装
npm install netparser
实例
import * as netparser from 'netparser';
netparser.baseAddress('b011:a2c2:7328:cc01:4ee7:e2ec:6269:babf/73');
// returns 'b011:a2c2:7328:cc01:4e80::'
netparser.broadcastAddress('192.168.0.50/24');
// returns '192.168.0.255'
netparser.findUnusedSubnets('192.168.0.0/22', ['192.168.1.0/24', '192.168.2.32/30']);
// returns ['192.168.0.0/24', '192.168.2.0/27', '192.168.2.36/30', '192.168.2.40/29', '192.168.2.48/28', '192.168.2.64/26', '192.168.2.128/25', '192.168.3.0/24']
netparser.ip(' [2001:db8:122:344:0:0:0::0:0:0:1] ');
// returns '2001:db8:122:344::1'
netparser.network(' 192.168.000.000/24 ');
// returns '192.168.0.0/24'
netparser.networkComesBefore('192.168.0.0/24', '10.0.0.0/8');
// returns false
netparser.networkContainsSubnet('192.168.0.0/16', '192.168.0.0/24');
// returns true
netparser.networksIntersect('192.168.0.0/23', '192.168.1.0/24');
// returns true
netparser.nextAddress('192.168.0.0');
// returns '192.168.0.1'
netparser.nextNetwork('192.168.0.0/24');
// returns '192.168.1.0/24'
netparser.rangeOfNetworks('192.168.1.2', '192.168.2.2');
// returns ['192.168.1.2/31', '192.168.1.4/30', '192.168.1.8/29', '192.168.1.16/28', '192.168.1.32/27', '192.168.1.64/26', '192.168.1.128/25', '192.168.2.0/31', '192.168.2.2/32']
netparser.sort(['255.255.255.255', '192.168.0.0/16', '192.168.2.3/31']);
// returns ['192.168.0.0/16', '192.168.2.3/31', '255.255.255.255/32']
netparser.summarize(['192.168.1.1', '192.168.0.0/16', '192.168.2.3/31']);
// returns ['192.168.0.0/16']
var matcher = new netparser.Matcher(['192.168.0.0/24', '192.168.2.0/23', '192.168.4.0/24']);
matcher.has('192.168.3.0');
// returns true
报告
- 简而言之,所有功能都只能回归
String, String[], boolean, or null。 。 。 . - 默认情况下,库将无声地失败
null当遇到错误时返回。 要覆盖此设置可选throwErrors参数改为True。 。 。 . - 默认情况下, 库会方便地遮盖
network当这样的操作有道理时,数值会输入其基本地址。 要覆盖此设置可选strict参数改为True在适用的情况下.
基准
npm run bench
'index.bench.ts' output:
baseAddress (netparser) x 1,881,378 ops/sec ±0.66% (95 runs sampled)
baseAddress (ip-address) x 1,355,975 ops/sec ±0.64% (88 runs sampled)
baseAddress (ipaddr.js) x 509,825 ops/sec ±2.07% (89 runs sampled)
baseAddress (netmask) x 326,042 ops/sec ±3.84% (82 runs sampled)
contains (netparser) x 883,418 ops/sec ±1.53% (84 runs sampled)
contains (ip-address) x 901,704 ops/sec ±1.44% (90 runs sampled)
contains (ipaddr.js) x 59,005 ops/sec ±13.38% (65 runs sampled)
contains (netmask) x 304,785 ops/sec ±1.77% (88 runs sampled)
'match.bench.ts' output:
create (netparser) x 11.91 ops/sec ±5.55% (34 runs sampled)
create (cidr-matcher) x 5.13 ops/sec ±5.43% (17 runs sampled)
create (ipaddr.js) x 28.78 ops/sec ±4.83% (50 runs sampled)
query (netparser) x 145,604 ops/sec ±1.25% (91 runs sampled)
query (cidr-matcher) x 1,035 ops/sec ±3.74% (83 runs sampled)
query (ipaddr.js) x 16.22 ops/sec ±1.76% (44 runs sampled)
API 密码
使用 docts
函数
baseAddressBaseAddress 返回给定子网地址的基址
源代码 :<>基础地址( ) ⇒
null | string<>
* 网络地址string- 网络地址,例如192.168.0.4/24
丢出错误? 吗?undefined | true | false- 阻止图书馆无声失败函数
broadcastAddressBradioAddress返回IPv4地址的广播地址.
请注意IPv6没有广播地址.
源代码 :<>广播地址( ) ⇒
null | string<>
* 网络string- 类似192.168.0.0/24的网络
丢出错误? 吗?undefined | true | false- 阻止图书馆无声失败函数
findUnusedSubnetsFind UnusedSubnets 返回未使用子网的数组,考虑到集合和兄弟子网
源代码 :<>查找未使用的子网( ) ⇒
null | string[]<>
合计string- 综合网络,如192.168.0.0/24
* 子网string[]- 诸如["192.168.0.0/24","192.168.08.128/26"等子网络阵列
严格? 吗?undefined | true | false- 不将地址自动遮盖到数据库地址
丢出错误? 吗?undefined | true | false- 阻止图书馆无声失败函数
ip解析一个 IP 地址
源代码 :<>ip () (中文(简体) ) ⇒
null | string<>
* 地址string- 地址为192.168.0.0或次网192.168.0.0/24
丢出错误? 吗?undefined | true | false- 阻止图书馆无声失败函数
network分析网络地址
源代码 :<>网络( ) ⇒
null | string<>
* 网络地址string- 类似192.168.0.0/24的网络
丢出错误? 吗?undefined | true | false- 阻止图书馆无声失败函数
networkComesBeforeNetworkComes Before return了数字网络顺序的布尔 .
请注意,IPv4出现在IPv6之前,而更大的网络出现在较小的网络之前.
源代码 :<>网络来之前( ) ⇒
null | true | false<>
* 网络string- 类似192.168.0.0/24的网络
* 其他网络string- 类似192.168.1.0/24的网络
严格? 吗?undefined | true | false- 不将地址自动遮盖到数据库地址
丢出错误? 吗?undefined | true | false- 阻止图书馆无声失败函数
networkContainsAddress网络ContainsAddress 验证地址位于网络内部
源代码 :<>网络 ⇒
null | true | false<>
* 网络string- 类似192.168.0.0/24的网络
* 地址string- 类似192.168.0.100的网络
严格? 吗?undefined | true | false- 不将地址自动遮盖到数据库地址
丢出错误? 吗?undefined | true | false- 阻止图书馆无声失败函数
networkContainsSubnet网络ContainsSubnet验证网络是有效的超级网络
源代码 :<>网络 ⇒
null | true | false<>
* 网络string- 像192.168.0.0/16这样的网络
* 子网string- 类似192.168.0.0/24的网络
严格? 吗?undefined | true | false- 不将地址自动遮盖到数据库地址
丢出错误? 吗?undefined | true | false- 阻止图书馆无声失败函数
networksIntersect网络Intersect 返回显示网络重叠的 bull
源代码 :<>网络接口( ) ⇒
null | true | false<>
* 网络string- 类似192.168.0.0/23的网络
* 其他网络string- 类似192.168.1.0/24的网络
严格? 吗?undefined | true | false- 不将地址自动遮盖到数据库地址
丢出错误? 吗?undefined | true | false- 阻止图书馆无声失败函数
nextAddressNextAddress 返回下一个地址
源代码 :<>下一个地址( ) ⇒
null | string<>
* 地址string-一个像192.168.0.0的地址
丢出错误? 吗?undefined | true | false- 阻止图书馆无声失败函数
nextNetworkNextNetwork返回大小相同的下个网络.
源代码 :<>下一个网络( ) ⇒
null | string<>
* 网络string- 类似192.168.0.0/24的网络
严格? 吗?undefined | true | false- 不将地址自动遮盖到数据库地址
丢出错误? 吗?undefined | true | false- 阻止图书馆无声失败函数
rangeOfNetworksRangeOfNetworks 返回一定范围的网络
源代码 :<>网络范围( ) ⇒
null | string[]<>
* 启动地址string- 地址是192.168.1.2号
* 停止定居string-一个像192.168.1.5的地址
丢出错误? 吗?undefined | true | false- 阻止图书馆无声失败函数
sort排序返回一系列排序的网络
源代码 :<>排序( ) ⇒
null | string[]<>
* 网络地址string[]- 一系列地址或子网
丢出错误? 吗?undefined | true | false- 阻止图书馆无声失败函数
summarize汇总返回给定网络列表的集合数组
源代码 :<>总结( ) ⇒
null | string[]<>
• 网络string[]- 一系列地址或子网
严格? 吗?undefined | true | false- 不将地址自动遮盖到数据库地址
丢出错误? 吗?undefined | true | false- 阻止图书馆无声失败