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

is-ip Build Status

Check if a string is an IP address

Install

$ npm install is-ip

Usage

const isIp = require('is-ip');

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

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

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

API

isIp(string)

Check if string is IPv4 or IPv6.

isIp.v4(string)

Check if string is IPv4.

isIp.v6(string)

Check if string is IPv6.

isIp.version(string)

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

isIp.version('192.168.0.1');
//=> 4

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

isIp.version('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

License

MIT © Sindre Sorhus

Current Tags

  • 3.1.0                                ...           latest (a year ago)

4 Versions

  • 3.1.0                                ...           a year ago
  • 3.0.0                                ...           a year ago
  • 2.0.0                                ...           3 years ago
  • 1.0.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 7
This Week 294
This Month 1,262
Last Day 287
Last Week 1,554
Last Month 6,208
Dependencies (1)
Dev Dependencies (3)
Dependents (126)

Copyright 2014 - 2016 © taobao.org |