The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


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' => '', '' );
  $resolver->add( 'Foobar'  => [ '', '' ] );
  # Check an IP
  my $ip = '';
  my $network = $resolver->find_first( $ip );
  print "IP $ip is in network $network";
  # prints... "IP 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.



The new constructor takes no arguments, and create a new and empty resolver.

Returns a new Net::IP::Resolver object.

add $network, $range, ...

The 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 $ip

The 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 <>


Net::IP, Net::IP::Match::XS,


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.