is-ip
Check if a string is an IP address
Last updated 2 years ago by sindresorhus .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install is-ip 
SYNC missed versions from official npm registry.

is-ip

Check if a string is an IP address

If you only need this for Node.js and don't care about browser support, you may want to use net.isIP instead. Note that it returns an integer instead of a boolean.

Install

npm install is-ip

Usage

import {isIP, isIPv4} from 'is-ip';

isIP('1:2:3:4:5:6:7:8');
//=> true

isIP('192.168.0.1');
//=> true

isIPv4('1:2:3:4:5:6:7:8');
//=> false

API

isIP(string)

Check if string is IPv6 or IPv4.

isIPv6(string)

Check if string is IPv6.

isIPv4(string)

Check if string is IPv4.

ipVersion(string)

Returns 6 if string is IPv6, 4 if string is IPv4, or undefined if string is neither.

import {ipVersion} from 'is-ip';

ipVersion('1:2:3:4:5:6:7:8');
//=> 6

ipVersion('192.168.0.1');
//=> 4

ipVersion('abc');
//=> undefined

Related

  • ip-regex - Regular expression for matching IP addresses
  • is-cidr - Check if a string is an IP address in CIDR notation
  • cidr-regex - Regular expression for matching IP addresses in CIDR notation

Current Tags

  • 5.0.0                                ...           latest (2 years ago)

6 Versions

  • 5.0.0                                ...           2 years ago
  • 4.0.0                                ...           3 years ago
  • 3.1.0                                ...           5 years ago
  • 3.0.0                                ...           6 years ago
  • 2.0.0                                ...           8 years ago
  • 1.0.0                                ...           10 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (2)
Dev Dependencies (3)
Dependents (2)

Copyright 2013 - present © cnpmjs.org | Home |