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

ipcheck

v0.1.0

Published

Super-efficient module to parse and check if an IP address is in a CIDR block. IPv4 and IPv6 supported.

Downloads

18,020

Readme

IPCheck

Travis Dependencies Join the chat at https://gitter.im/gosquared/ipcheck

NPM

Quickly parses IP addresses, allowing them to be checked for CIDR matches.

Converts IPv4 to IPv6 to keep the process seamless and allow transitional IPs.

Install

npm install ipcheck --save

Usage

Quick

To easily check an IP and a CIDR without any extra thrills...

var IPCheck = require('ipcheck');
IPCheck.match('192.168.0.1', '192.168.0.1/32'); //= true

Ordinary

Allows you to individually validate and re-use different IPs.

var IPCheck = require('ipcheck');
var ip = new IPCheck('192.168.0.1');
var cidr = new IPCheck('192.168.0.1/32');

ip.match(cidr); //= true

IPv6

Works seamlessly!

IPCheck.match('FE80:0000:0000:0000:0202:B3FF:FE1E:8329', 'FE80:0000:0000:0000:0202:B3FF:FE1E:8329/128'); //= true

IPv4 and IPv6 transitional

As all IPv4 addresses are converted to IPv6, transitional IPs are supported.

var ip = new IPCheck('192.168.0.1');
var ipv4cidr = new IPCheck('192.168.0.1/32');
var ipv6cidr = new IPCheck('::ffff:192.168.0.1/128');
ip.match(ipv4cidr); //= true
ip.match(ipv6cidr); //= true

To convert a CIDR from IPv4 to IPv6, the mask simply has 96 added to it.

Invalid IPs/errors

IPCheck is designed to not throw errors.

If you'd like to know an address is valid, simply read the valid property...

var ip = new IPCheck('192.168.0.1');
ip.valid; //= true

var badIP = new IPCheck([ 'huh?' ]);
badIP.valid; //= false

var anotherBadIP = new IPCheck('silly.ip');
anotherBadIP.valid; //= false

// Match always returns false if either the IP or the CIDR are invalid
IPCheck.match('hi', 'oh/no');

Other

Benchmarks

npm run benchmark - simply compares this to ipaddr.js and ip-address modules in places. The TL;DR of it is that ipcheck is reliably faster.

Tests

npm test - ensure everything works!