Changeset 54 for trunk/dnsbl/DNSBL.pm


Ignore:
Timestamp:
12/11/14 17:22:28 (9 years ago)
Author:
Kris Deugau
Message:

/trunk/dnsbl

Extend the number of layers/depth from 3 to 7 internally. Note that only

5 are exposed in the "add" UI.

Add support to extract the CIDR range when a WHOIS lookup gives a non-CIDR

range.

Fix tracking of "seen" IPs creating the browse display.
Add the new DNSBLweb.pm to the Makefile MANIFEST, and bump the version in

the Makefile

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dnsbl/DNSBL.pm

    r50 r54  
    272272
    273273
     274# take an arbitrary IP range and an IP, and return the CIDR block (if any) the IP is in.
     275sub range2cidr {
     276  my $self = shift;
     277  my $rstart = shift;
     278  my $rend = shift;
     279  my $ip = shift;
     280
     281  $rstart = new NetAddr::IP $rstart;
     282  $rend = new NetAddr::IP $rend;
     283  # Basic algoithm:  Set the mask on the IP, and see if both $rstart and $rend
     284  # are within the range defined by that IP/mask.  Continue making the mask
     285  # larger until success.
     286
     287  my $mask;
     288  for ($mask = 32; $mask > 0; $mask--) {
     289    my $ip = NetAddr::IP->new("$ip/$mask");
     290    if (NetAddr::IP->new($ip->network->addr)   >= $rstart    &&
     291        NetAddr::IP->new($ip->broadcast->addr) <= $rend) {
     292      next;
     293    } else {
     294      $mask++;
     295      last;
     296    }
     297  }
     298  my $realnet = NetAddr::IP->new("$ip/$mask")->network;
     299
     300  return "$realnet";
     301} # end range2cidr()
     302
     303
    274304# add a block.  requires the orgid
    275305##fixme needs error handling
Note: See TracChangeset for help on using the changeset viewer.