I'd like to write a function in Javascript along the lines of:
in_subnet(ip, network, slash) {
...
}
in_subnet('1.2.3.4', '1.2.0.0', 16) # True, since it's in 1.2.0.0/16
in_subnet('1.2.3.4', '1.2.0.0', 24) # False, since it's not in 1.2.0.0/24
Should I write it from scratch, or are there some good libraries I could use? Or is the entire function already written and in the public domain?