Net::IP::Resolver - Resolve IPs to a particular network
# Create the resolver and add some networks my $resolver = Net::IP::Resolve->new; $resolver->add( 'Comcast' => '18.104.22.168/8', '22.214.171.124/10' ); $resolver->add( 'Foobar' => [ '126.96.36.199/24', '188.8.131.52/24' ] ); # Check an IP my $ip = '184.108.40.206'; my $network = $resolver->find_first( $ip ); print "IP $ip is in network $network"; # prints... "IP 220.127.116.11 is in network Comcast";
Net::IP::Resolver provides a mechanism for registering a number of different networks (specified by a set of ip ranges), and then finding the network for a given IP based on this specification.
The identifier for a network can be any defined value that you wish.
Thus you can resolve to numeric identifiers, names, or even to objects representing the networks.
new constructor takes no arguments, and create a new and empty resolver.
Returns a new
add method adds a network to the resolver. It takes as argument an identifier for the network, which can be
any defined value, including an object of any type, followed by a set of 1 or more IP ranges, in the format used by Net::IP::Match::XS (which this class uses for the actual ip matching).
Returns true if the network was added, or
undef if passed incorrect arguments.
find_first method takes an IP address as argument, and checks it against each network to find the first one that matches.
The assumption made by
find_first is that each network in the resolver occupies a unique and non-overlapping set of ranges, and thus only any ip can only ever resolve to one network
Returns the network identifier as originally provided, or
undef if the ip is not provided, or the resolver cannot match it to any network.
All bugs should be filed via the bug tracker at
For other issues, or commercial enhancement and support, contact the author
Adam Kennedy <firstname.lastname@example.org>
Copyright 2005 - 2006 Adam Kennedy.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.