JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7512
  • Score
    100M100P100Q123488F
  • License MIT

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

Package Exports

  • check-ip

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (check-ip) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

check-ip

Known Vulnerabilities

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

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: javascript { 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