subnet-check
This is a fork which works independantly of node.js to be able to be used in the browser.
Check if an IPv4 or IPv6 address is contained in the given CIDR subnet.
- Small
- Fast
- Simple syntax
- Full test coverage
- TypeScript-friendly
- Zero dependencies
Installation
npm i -S louispvb/subnet-check
Usage
const isInSubnet = ; console; // falseconsole; // true console; // falseconsole; // true
More ways to use it
Test multiple subnets at once
You can pass an array instead of a single subnet.
const inAnySubnet = ;
This module recognizes several special classes of addresses.
Private addresses
;
True if the address is in a private/internal address range, such as 192.168.1.1
or similar, or an IPv6 Unique Local Address.
Localhost addresses
;
True if the address represents the localhost, such as 127.0.0.1
or ::1
.