npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cidr-generator

v1.0.3

Published

[![Build Status via Travis CI](https://travis-ci.org/Furchin/CIDR-Generator.svg?branch=master)](https://travis-ci.org/Furchin/CIDR-Generator) [![NPM version](http://img.shields.io/npm/v/cidr-generator.svg)](https://www.npmjs.org/package/cidr-generator)

Downloads

3

Readme

cidr-generator

Build Status via Travis CI NPM version

Given a list of IP addresses to blacklist and a maximum number of CIDR blocks to use, return a set of CIDR blocks covering the blacklist with minimal collateral damage (non-blacklisted IP addresses which fall into the CIDR blocks returned).

This is ideal for generating CIDR-based blacklist rulesets to block malicious traffic originating from particular IP addresses where the total number of CIDRs in the ruleset is limited (eg, AWS VPC ACLs allow only 20 rules) while minimizing the impact to non-malicious IP addresses.

In future versions of this package the CIDR block generation logic will avoid the whitelisted IP addresses; in the current version however it simply reports how many whitelisted IP addresses fall into each returned CIDR block.

Install with:

npm install cidr-generator

Usage

Parameters

blacklist - An array of IPv4-formatted IP address strings which will be covered by the resulting CIDR blocks. whitelist - An array of IPv4-formatted IP address strings which should not be covered by the CIDR blocks. maxBlocks - The maximum number of CIDR blocks to return.

Return Value

An array of objects whose length will be maxBlocks or less. Each object will contain the following fields:

CIDR - a string representing a CIDR block (eg, 127.0.0.0/30) blacklistedIPs - the number of IP addresses from the blacklist covered by the CIDR block. whitelistedIPs - the number of IP addresses from the whitelist covered by the CIDR block. collateralDamage - the number of IP addresses in the CIDR block that are not in the blacklist. (This quantity includes IP addresses appearing on the whitelist.)

Examples

var generator = require('cidr-generator');

// Example where you have a set of IPs to blacklist using only a single CIDR block:
var ips = [
    // contiguous block
    '127.0.0.0',
    '127.0.0.1',
    '127.0.0.2',
    '127.0.0.3'
];
var cidrs = generator(ips, null, 1);
console.log('Blocking: ' + cidrs[0].CIDR);

// Example where you have a set of IPs to blacklist using three CIDR blocks:
cidrs = generator(ips, null, 3);
console.log('Blocking: ' + cidrs[0].CIDR);
console.log('Blocking: ' + cidrs[1].CIDR);
console.log('Blocking: ' + cidrs[2].CIDR);