blockList.check(address[, type])
address<string> | <net.SocketAddress> 要检查的 IP 地址type<string>'ipv4'或'ipv6'。 默认值:'ipv4'。- 返回: <boolean>
如果给定的 IP 地址与添加到 BlockList 的任何规则匹配,则返回 true。
const blockList = new net.BlockList();
blockList.addAddress('123.123.123.123');
blockList.addRange('10.0.0.1', '10.0.0.10');
blockList.addSubnet('8592:757c:efae:4e45::', 64, 'ipv6');
console.log(blockList.check('123.123.123.123')); // 打印: true
console.log(blockList.check('10.0.0.3')); // 打印: true
console.log(blockList.check('222.111.111.222')); // 打印: false
// IPv4 地址的 IPv6 表示法有效:
console.log(blockList.check('::ffff:7b7b:7b7b', 'ipv6')); // 打印: true
console.log(blockList.check('::ffff:123.123.123.123', 'ipv6')); // 打印: trueaddress<string> | <net.SocketAddress> The IP address to checktype<string> Either'ipv4'or'ipv6'. Default:'ipv4'.- Returns: <boolean>
Returns true if the given IP address matches any of the rules added to the
BlockList.
const blockList = new net.BlockList();
blockList.addAddress('123.123.123.123');
blockList.addRange('10.0.0.1', '10.0.0.10');
blockList.addSubnet('8592:757c:efae:4e45::', 64, 'ipv6');
console.log(blockList.check('123.123.123.123')); // Prints: true
console.log(blockList.check('10.0.0.3')); // Prints: true
console.log(blockList.check('222.111.111.222')); // Prints: false
// IPv6 notation for IPv4 addresses works:
console.log(blockList.check('::ffff:7b7b:7b7b', 'ipv6')); // Prints: true
console.log(blockList.check('::ffff:123.123.123.123', 'ipv6')); // Prints: true