amulllb
amulllb

Reputation: 3166

ipv4/ipv6 network address match in node-js

I am looking for something like python's netaddr.IPNetwork in node.js. Basically, i have IP network addresses like 1.1.1.1/30, 1::/128 and want to validate in the backend in express if the data provided by user is valid ip network?

Thanks,

Upvotes: 3

Views: 1910

Answers (1)

amulllb
amulllb

Reputation: 3166

found a good library: https://github.com/whitequark/ipaddr.js

var ipaddr = require('ipaddr.js');
var addr = ipaddr.parse("2001:db8:1234::1");
var range = ipaddr.parse("2001:db8::");
addr.match(range, 32); // => true

Upvotes: 4

Related Questions