Net::CIDR::Lookup

A Perl class that implements a lookup table indexed by IPv4 networks or hosts
Download

Net::CIDR::Lookup Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Matthias Bethke
  • Publisher web site:
  • http://search.cpan.org/~mbethke/

Net::CIDR::Lookup Tags


Net::CIDR::Lookup Description

A Perl class that implements a lookup table indexed by IPv4 networks or hosts Net::CIDR::Lookup is a Perl class that implements a lookup table indexed by IPv4 networks or hosts. * Addresses are accepted in numeric form (integer with separate netbits argument), as strings in CIDR notation or as IP address ranges * Overlapping or adjacent networks are automatically coalesced if their associated values are equal. * The table is implemented as a binary tree so lookup and insertion take O(log n) time.Methods generally return a true value on success and undef on error. In the latter case, an error message will be available in $Net::CIDR::Lookup::errstrSYNOPSIS use Net::CIDR::Lookup; $cidr = Net::CIDR::Lookup->new; $cidr->add("192.168.42.0/24",1); # Add first network, value 1 $cidr->add_num(167772448,27,2); # 10.0.1.32/27 => 2 $cidr->add("192.168.43.0/24",1); # Automatic coalescing to a /23 $cidr->add("192.168.41.0/24",2); # Stays separate due to different value $cidr->add("192.168.42.128/25",2); # Error: overlaps with different value $h = $cidr->dump; # Convert tree to a hash print "$k => $v\n" while(($k,$v) = each %$h); # Output (order may vary): # 192.168.42.0/23 => 1 # 10.0.1.32/27 => 2 # 192.168.41.0/24 => 2 $cidr->walk(sub { my ($addr, $bits, $val) = @_; print join('.', unpack 'C*', pack 'N', $addr), "/$bits => $val\n" } ); # Output (fixed order): # 10.0.1.32/27 => 2 # 192.168.41.0/24 => 2 # 192.168.42.0/23 => 1 $cidr->clear; # Remove all entries $cidr->add_range('1.2.3.11 - 1.2.4.234', 42); # Add a range of addresses, automatically split into CIDR blocks $h = $cidr->dump; print "$k => $v\n" while(($k,$v) = each %$h); # Output (order may vary): # 1.2.4.128/26 => 42 # 1.2.3.32/27 => 42 # 1.2.3.64/26 => 42 # 1.2.4.234/32 => 42 # 1.2.4.0/25 => 42 # 1.2.3.12/30 => 42 # 1.2.3.128/25 => 42 # 1.2.3.16/28 => 42 # 1.2.4.224/29 => 42 # 1.2.4.232/31 => 42 # 1.2.3.11/32 => 42 # 1.2.4.192/27 => 42 Requirements: · Perl


Net::CIDR::Lookup Related Software