What is is-my-ip-valid?
The is-my-ip-valid npm package is a utility for validating IP addresses. It supports both IPv4 and IPv6 formats and provides simple methods to check if an IP address is valid.
What are is-my-ip-valid's main functionalities?
Validate IPv4
This feature allows you to validate if a given string is a valid IPv4 address.
const isMyIpValid = require('is-my-ip-valid');
const ipv4 = '192.168.1.1';
const isValidIPv4 = isMyIpValid(ipv4);
console.log(`Is ${ipv4} a valid IPv4 address?`, isValidIPv4);
Validate IPv6
This feature allows you to validate if a given string is a valid IPv6 address.
const isMyIpValid = require('is-my-ip-valid');
const ipv6 = '2001:0db8:85a3:0000:0000:8a2e:0370:7334';
const isValidIPv6 = isMyIpValid(ipv6);
console.log(`Is ${ipv6} a valid IPv6 address?`, isValidIPv6);
Custom Validation
This feature allows you to create a custom validator for specific IP address formats, such as IPv4 with CIDR notation.
const isMyIpValid = require('is-my-ip-valid');
const customValidator = isMyIpValid({ version: 4, cidr: true });
const ip = '192.168.1.1/24';
const isValid = customValidator(ip);
console.log(`Is ${ip} a valid IPv4 CIDR address?`, isValid);
Other packages similar to is-my-ip-valid
ip
The 'ip' package provides utilities for IP address manipulation, including validation, conversion, and subnet calculations. It offers more comprehensive functionality compared to is-my-ip-valid, such as converting IP addresses to different formats and performing subnet calculations.
ipaddr.js
The 'ipaddr.js' package is a library for manipulating IPv4 and IPv6 addresses in JavaScript. It provides validation, parsing, and comparison functions. It is more feature-rich than is-my-ip-valid, offering detailed parsing and manipulation capabilities.
netmask
The 'netmask' package is used for IP address and network mask calculations. It allows for validation, subnet calculations, and IP range checks. It is more focused on network-related calculations compared to is-my-ip-valid.
Is my IP valid
A small lib to validate IP addresses.
Installation
npm install --save is-my-ip-valid
Usage
const validator = require('is-my-ip-valid')
const validate = validator()
const validate4 = validator({ version: 4 })
const validate6 = validator({ version: 6 })
console.log(validate('127.0.0.1'))
console.log(validate4('127.0.0.1'))
console.log(validate6('127.0.0.1'))
console.log(validate('2001:0db8:85a3:0000:0000:8a2e:0370:7334'))
console.log(validate4('2001:0db8:85a3:0000:0000:8a2e:0370:7334'))
console.log(validate6('2001:0db8:85a3:0000:0000:8a2e:0370:7334'))
Acknowledgements
The code is mostly based on this wonderful library: beaugunderson/ip-address
All regexes used are audited for catastrophic backtracking by this module: substack/safe-regex