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

check-ip

v1.1.1

Published

Code that will validate an IP address for correct format and give additional information about the type of IP address.

Downloads

15,412

Readme

check-ip

Known Vulnerabilities

A simple module that will take an IP address as input and perform the following:

  • Validate the IP address for proper format and number range
  • Remove any leading zeros in each octet
  • Return a tested ("boiled") IP address
  • Indicate if the IP address is part of the bogons list (https://en.wikipedia.org/wiki/Bogon_filtering)
  • Indicate if the IP address is part of the multicast IP range (https://en.wikipedia.org/wiki/IP_multicast)
  • Indicate if the IP address is an Automatic Private IP Address aka APIPA (http://www.webopedia.com/TERM/A/APIPA.html)
  • Indicate if the IP address is an RFC1918 IP address aka private IP address (https://tools.ietf.org/html/rfc1918)
  • Indicate if the IP address is a public IP address

Install

npm install check-ip

Usage

Import the module and give it the IP address to be tested as a parameter:

var checkIp = require('check-ip');

checkIp('8.8.8.8');

check-ip will return an object similar to the following:

{ originalIp: '8.8.8.8',
  boiledIp: '8.8.8.8',
  isValid: true,
  isBogon: false,
  isApipa: false,
  isMulticast: false,
  isRfc1918: false,
  isPublicIp: true }

You can use any of the properties of the returned object in your code to test for specific use cases.

Methods

  • None

Examples

Working example of an IP address being tested as a valid public IP address (copy this first code snippet, save in a file and use for testing):

var checkIp = require('check-ip');
var ipAddress = '8.8.8.8';

var response = checkIp(ipAddress);
if (response.isValid && response.isPublicIp) {
  console.log("IP address " + response.boiledIp + " is a valid public IP.");
}

Example of testing an IP address to make sure it is valid and then using the boiled IP in your code:

var checkIp = require('check-ip');
    
// IP address determined to be from a previously defined arguments array elsewhere.
var ip = arg[2];

var response = checkIp(ip);
if (!response.isValid) {
  console.log("Please enter a different IP address.  That one is not valid.");
} else {
  console.log("IP address " + response.boiledIp + " as a valid IP address.");

  // More code goes here to use response.boiledIp in your code.
  {...}

}

Here is example output demonstrating the module 'boiling' the leading zero off of the second octet of the supplied IP address:

{ originalIp: '10.020.30.40',
  boiledIp: '10.20.30.40',
  isValid: true,
  isBogon: true,
  isApipa: false,
  isMulticast: false,
  isRfc1918: true,
  isPublicIp: false }

Testing

Run automated tests for Node.js:

npm run test