1.0.3 • Published 2 years ago

fast-cidr-match v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Fast CIDR Matcher

This library determines if a given IPv4 is contained within a list if IP addresses and subnets in approximately O(log n) time—which is much faster than many existing libraries.

Installation

npm i fast-cidr-match

API

Create a FastCIDRMatcher

const FastCIDRMatcher = require('fast-cidr-match');

//Constructor takes an array of CIDRs/IPv4s
const fastCidrMatcher = new FastCIDRMatcher(['192.168.0.0/16', '172.16.32,80', '10.0.0.0/8']); 

ContainsIP

fastCidrMatcher.containsIP('192.168.1.1') //True
fastCidrMatcher.containsIP('this is not an ip') //False

CompressDatabase

Note: This feature is somewhat experimental and currently prevents additional data from being added to the match list. May cause a slight performance degredation (< 500ms in 1,000,000 IP benchmark) but makes database approximatley 20% smaller in benchmark.

fastCidrMatcher.compressDatabase() 

Benchmark

1,000,000 random IPs from a list of over 22,000 subnets

LibraryVersionExecution time
FastCIDRMatcher1.0.02342 ms
cidr-matcher2.1.157019 ms