Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sindresorhus/is-ip
Check if a string is an IP address
https://github.com/sindresorhus/is-ip
Last synced: 3 days ago
JSON representation
Check if a string is an IP address
- Host: GitHub
- URL: https://github.com/sindresorhus/is-ip
- Owner: sindresorhus
- License: mit
- Created: 2014-09-06T11:52:15.000Z (over 10 years ago)
- Default Branch: main
- Last Pushed: 2023-08-05T13:42:06.000Z (over 1 year ago)
- Last Synced: 2025-02-05T12:06:32.550Z (10 days ago)
- Language: JavaScript
- Size: 18.6 KB
- Stars: 113
- Watchers: 7
- Forks: 15
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- Funding: .github/funding.yml
- License: license
- Security: .github/security.md
Awesome Lists containing this project
- awesome-nodejs - is-ip - Check if a string is an IP address. (Repository / Check/Detect)
README
# 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`](https://nodejs.org/api/net.html#net_net_isip_input) instead. Note that it returns an integer instead of a boolean.
## Install
```sh
npm install is-ip
```## Usage
```js
import {isIP, isIPv4} from 'is-ip';isIP('1:2:3:4:5:6:7:8');
//=> trueisIP('192.168.0.1');
//=> trueisIPv4('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.
```js
import {ipVersion} from 'is-ip';ipVersion('1:2:3:4:5:6:7:8');
//=> 6ipVersion('192.168.0.1');
//=> 4ipVersion('abc');
//=> undefined
```## Related
- [ip-regex](https://github.com/sindresorhus/ip-regex) - Regular expression for matching IP addresses
- [is-cidr](https://github.com/silverwind/is-cidr) - Check if a string is an IP address in CIDR notation
- [cidr-regex](https://github.com/silverwind/cidr-regex) - Regular expression for matching IP addresses in CIDR notation