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

ip-range-check

v0.2.0

Published

Check whether an IP(v4 or v6) is in an CIDR range

Downloads

1,893,139

Readme

IP Range Check

Build Status

NPM

This module lets you check if an IP matches one or more IP's or CIDR ranges. It handles IPv6, IPv4, and IPv4-mapped over IPv6 addresses.

It accepts either:

  • A single CIDR or IP string, e.g. "125.19.23.0/24", or "2001:cdba::3257:9652", or "62.230.58.1"
  • An array of CIDR and/or IP strings, e.g. ["125.19.23.0/24", "2001:cdba::3257:9652", "62.230.58.1"]

Importantly, it cannot match an IPv4 address to an IPv6 CIDR or vice versa, (IPv4-mapped IPv6 addresses notwithstanding).

Installing

npm install ip-range-check --save

IPv4

var ipRangeCheck = require("ip-range-check");

// Checks CIDR
ipRangeCheck("192.168.1.1", "102.1.5.2/24")
// > false
ipRangeCheck("192.168.1.1", "192.168.1.0/24")
// > true

// Checks if IP matches string
ipRangeCheck("192.168.1.1", "192.168.1.1")
// > true

// Checks array of CIDR's and string
ipRangeCheck("192.168.1.1", ["102.1.5.2/24", "192.168.1.0/24", "106.1.180.84"])
// > true

// Compare IPv6 with IPv4
ipRangeCheck("195.58.1.62", ["::1/128", "125.92.12.53"])
// > false

IPv6

var ipRangeCheck = require("ip-range-check");

// Handles IPv6 in the same fashion as IPv4
ipRangeCheck("::1", "::2/128")
// > false
ipRangeCheck("::1", ["::2", "::3/128"])
// > false
ipRangeCheck("2001:cdba::3257:9652", "2001:cdba::3257:9652/128")
// > true

// IPv4-mapped IPv6 addresses are automatically converted back to IPv4 addresses
// and will match against IPv4 CIDR/IP's.
ipRangeCheck("0:0:0:0:0:FFFF:222.1.41.90", "222.1.41.0/24")
// > true

// IPv6 addresses/CIDR's are normalised
ipRangeCheck("2001:cdba:0000:0000:0000:0000:3257:9652", ["2001:cdba::3257:9652"])
// > true

Developing

To run the tests:

npm test