Mcheck
Bun

method

net.BlockList.check

address: SocketAddress
): boolean;

Returns true if the given IP address matches any of the rules added to theBlockList.

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
@param address

The IP address to check

address: string,
type?: IPVersion
): boolean;

Returns true if the given IP address matches any of the rules added to theBlockList.

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
@param address

The IP address to check

@param type

Either 'ipv4' or 'ipv6'.

Referenced types

  • readonly address: string

    Either 'ipv4' or 'ipv6'.

  • readonly family: IPVersion

    Either 'ipv4' or 'ipv6'.

  • readonly flowlabel: number
  • readonly port: number
  • static parse(
    input: string
    ): undefined | SocketAddress;
    @param input

    An input string containing an IP address and optional port, e.g. 123.1.2.3:1234 or [1::1]:1234.

    @returns

    Returns a SocketAddress if parsing was successful. Otherwise returns undefined.

type IPVersion = 'ipv4' | 'ipv6'