Reputation: 3166
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
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