Skip to content

Typescript implementation for using CIDR masks for address filtering.

License

Notifications You must be signed in to change notification settings

ChainSafe/netmask

Repository files navigation

@chainsafe/netmask

Typescript implementation for using CIDR masks for address filtering. Heavily inspired by go implementation.

Features

How to use

npm i -s @chainsafe/netmask

or yarn add @chainsafe/netmask

Example usage:

import {IpNet} from "@chainsafe/netmask"

new IpNet("192.168.0.1/24").contains("192.168.0.16")
new IpNet("192.168.0.1", "24").contains("192.168.0.16")
new IpNet("2001:db8::/128").contains("2001:db8::")
new IpNet("192.168.0.1", "255.255.255.0").contains("192.168.0.16")

Quick start

  1. yarn
  2. yarn run build
  3. yarn run test