5

I use NetAddr and ipaddr-py to calculate subnet containment in Python, but I'm looking to start using client side logic to determine containment. I could probably figure out how to implement basic bitmask-based logic, but I'd rather use something more general and well-supported/optimized.

What I want to do is basically this:

function filter_by_containment(candidate_subnets, ipaddr_or_cidr) {
    accepted = [];
    for (i = 0; i < candidate_subnets.length; i++) {
        if (candidate_subnets[i].contains(ipaddr_or_cidr)) {
            accepted.append(candidate_subnets[i]);
        }
    }
    return accepted;
}

(note; I'm not a Javascript expert, so this is likely crap syntax. I'm also using JQuery and some other stuff, but in order to minimize the scale of the example I've used a simple, crappy loop)

Chris R
  • 17,546
  • 23
  • 105
  • 172

0 Answers0