GithubHelp home page GithubHelp logo

ip-cidr's Introduction

Install

npm install ip-cidr

About

Module for working with CIDR (v4, v6). Based on ip-address

Example

const CIDR = require("ip-cidr");

let cidr = new CIDR("50.165.190.0/23"); 

if(!cidr.isValid()) {
    // something 
}

cidr.start(); // get start ip as string
cidr.end({ asBigInteger: true }); // get end ip as big integer

let data = [];

let fn = (ip) => {
    // do something with each element of CIDR range    
    data.push(ip) // ip is "ip-address" module object, because of option asAddressObject is true 
}

cidr.arrayAction(fn, { asAddressObject: true });
cidr.toArray({ asBigInteger: true }); // get array of all ip in CIDR range as big integer;
cidr.toRange(); // get array of start and end ip as string [startIpAsString, endIpAsString]

API

.formatIP(address, [options])

returns the "ip-address" module object in the necessary format
options are the same in all of the library functions and might include asBigInteger, asAddressObject or asString (by default)

.start([options])

get start ip

.end([options])

get end ip

.toString()

get string cidr as "50.165.190.0/23"

.toRange([options])

get array of start and end ip [startIp, endIp]

.toObject([options])

get object of start and end ip {start: startIp, end: endIp}

.toArray([options], [results])

get array of all ip in CIDR range
you can get information by chunks using options.from and options.limit
this options might be integer or big integer("jsbn" instance)
you can pass second argument "results" (object) to get all chunk pagination information

.arrayAction(fn, [options], [results])

run fn for every element of CIDR range
you can use the same chunk options as in .toArray

ip-cidr's People

Contributors

ortexx avatar bf-cortex avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.