netaddr.js
Node.js utility package for working with IP addresses and CIDR ranges.
Installation
$ npm install netaddr --save
Usage
var Addr = require('netaddr').Addr;
var localhost = Addr('127.0.0.1');
var subnet = Addr('10.0.0.0/16');
var subnet = Addr(167772160, 16);
var intval = Addr('127.0.0.1').toInt();
var network = subnet.network();
var broadcast = subnet.broadcast();
subnet.contains(Addr('10.0.3.0/24'));
subnet.intersect(Addr('10.0.3.0/24'));
localhost.increment();
localhost.decrement();
Attempts to create an invalid Addr
will throw an Error
.
Limitations
Currently only IPv4 is supported, though there are plans to add IPv6 support.
This is complicated by the fact JavaScript does not support 64-bit integers,
let alone 128-bit integers.
Copyright & License
Copyright © 2015 Chris Corbyn. See the LICENSE file for details.