
Product
Introducing License Overlays: Smarter License Management for Real-World Code
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.
A library of useful functions related to IP (v4 and v6).
# Using npm
$ npm install --save ip-utils
# or Using yarn
$ yarn install --save ip-utils
Browser
// Import the Library
import * as ip from 'ip-util';
// Use any of the contained methods
ip.validIp('1.1.1.1'); // True
// Alternatively - import functions selectively
import { validIp } from 'ip-util'
validIp('1.1.1.1'); // True
NodeJS
// Import the Library
const ip = require('ip-util');
// Use any of the contained methods
ip.validIp('1.1.1.1'); // True
// IP Object
ip('1.1.1.1')
// Can be chained with
ip('1.1.1.1').isValid() // True
ip('1.1.1.1').isReserved() // False
ip('1.1.1.1').isPrivate() // False
ip('1.1.1.1').getOctet(1) // '1'
ip('1.1.1.1').getOctetArray() // ['1', '1', '1', '1']
ip('1.1.1.1').containedBy('1.2.3.4/8') // True
// Subnet Object
subnet('192.168.1.1/24')
// Can be chained with
subnet('192.168.1.1/24').networkAddress() // '192.168.1.0
subnet('192.168.1.1/24').broadcastAddress() // '192.168.1.255
subnet('192.168.1.1/24').firstHost() // '192.168.1.1
subnet('192.168.1.1/24').lastHost() // '192.168.1.254
subnet('192.168.1.1/24').mask() // '255.255.255.0
subnet('192.168.1.1/24').contains('192.168.1.143') // True
subnet('192.168.1.1/24').info()
/*
{
networkAddress: '192.168.1.0',
broadcastAddress: '192.168.1.255',
numberHosts: 254,
inclusiveNumberHosts: 256,
firstHostAddress: '192.168.1.1',
lastHostAddress: '192.168.1.254',
mask: '255.255.255.0',
cidrMask: 24
}
*/
// All individual Functions
isValidIp('54.34.2.12') // True
isValidIpv4('12.21.2.1') // True
isValidIpv6('fe80:0:0:0:204:61ff:fe9d:f156') // True
toLong('192.168.1.1') //3232235777
fromLong(3232235777) // 192.168.1.1
toString(3232235777) // As Above (deprecated)
isPrivate('2.3.4.5') // False
isReserved('192.168.2.1') // True
getOctetArray('50.11.12.13') // ['50', '11', '12', '13']
getOctet('50.11.12.13', 2) // '11'
cidrInfo('192.168.1.1/24')
/*
{
networkAddress: '192.168.1.0',
broadcastAddress: '192.168.1.255',
numberHosts: 254,
inclusiveNumberHosts: 256,
firstHostAddress: '192.168.1.1',
lastHostAddress: '192.168.1.254',
mask: '255.255.255.0',
cidrMask: 24
}
*/
subnetInfo('192.168.1.1', '255.255.255.0') // As above
broadcastAddress('12.13.14.150/25') // '12.13.14.255'
networkAddress('12.13.14.150/25') // '12.13.14.128'
firstHost('12.13.14.150/25') // '12.13.14.129'
lastHost('12.13.14.150/25') // '12.13.14.254'
numberHosts('12.13.14.150/25') // 126
mask('12.13.14.150/25') // '255.255.255.128'
maskToCidr('255.255.255.0') // '24'
cidrToMask('43.23.2.65/27') // 27
contains('192.168.1.0/25', '192.168.1.50') // True
Any and contributions are very welcome - be it:
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
The project uses commitizen to standardise commits in format:
<type>(<scope>): <subject>
ip-utils is released under the MIT license
FAQs
Library of useful functions related to IP
We found that ip-utils demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.
Product
Socket’s precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.