IP Util Functions Library
A library of useful functions related to IP (v4 and v6).
Installation
# Using npm
$ npm install --save ip-utils
# or Using yarn
$ yarn install --save ip-utils
Browser
import * as ip from 'ip-util';
ip.validIp('1.1.1.1');
import { validIp } from 'ip-util'
validIp('1.1.1.1');
NodeJS
const ip = require('ip-util');
ip.validIp('1.1.1.1');
Usage
ip('1.1.1.1')
ip('1.1.1.1').isValid()
ip('1.1.1.1').isReserved()
ip('1.1.1.1').isPrivate()
ip('1.1.1.1').getOctet(1)
ip('1.1.1.1').getOctetArray()
ip('1.1.1.1').containedBy('1.2.3.4/8')
subnet('192.168.1.1/24')
subnet('192.168.1.1/24').networkAddress()
subnet('192.168.1.1/24').broadcastAddress()
subnet('192.168.1.1/24').firstHost()
subnet('192.168.1.1/24').lastHost()
subnet('192.168.1.1/24').mask()
subnet('192.168.1.1/24').contains('192.168.1.143')
subnet('192.168.1.1/24').info()
isValidIp('54.34.2.12')
isValidIpv4('12.21.2.1')
isValidIpv6('fe80:0:0:0:204:61ff:fe9d:f156')
toLong('192.168.1.1')
fromLong(3232235777)
toString(3232235777)
isPrivate('2.3.4.5')
isReserved('192.168.2.1')
getOctetArray('50.11.12.13')
getOctet('50.11.12.13', 2)
cidrInfo('192.168.1.1/24')
subnetInfo('192.168.1.1', '255.255.255.0')
broadcastAddress('12.13.14.150/25')
networkAddress('12.13.14.150/25')
firstHost('12.13.14.150/25')
lastHost('12.13.14.150/25')
numberHosts('12.13.14.150/25')
mask('12.13.14.150/25')
maskToCidr('255.255.255.0')
cidrToMask('43.23.2.65/27')
contains('192.168.1.0/25', '192.168.1.50')
Contributing
Any and contributions are very welcome - be it:
- features that you implement yourself and then PR back.
- Ideas/Requests for new features.
- Suggestions for improvements.
New Functions can be written in src directory and then added as export in src/index.ts
Corresponding unit tests can be written in spec directory
Commit Format
The project uses commitizen to standardise commits in format:
<type>(<scope>): <subject>
Workflow is as follows:
- Mark issue your working with label - Status:In Progress
- Implement fix/feature
- Submit PR to develop branch
- PR will be reviewed/merged
- Upon milestones develop will be merged to master
- Master commits spawn a CI job to deploy new version to npm
License
ip-utils is released under the MIT license