Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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,

like image 755
amulllb Avatar asked Nov 20 '25 20:11

amulllb


1 Answers

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
like image 107
amulllb Avatar answered Nov 23 '25 09:11

amulllb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!