1.1.1 • Published 7 years ago

check-ip v1.1.1

Weekly downloads
969
License
MIT
Repository
github
Last release
7 years ago

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:

{ 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