As long as you don't mean blindingly fast and huge. You want Net::Netmask.
#!/usr/bin/env perl use strict; use warnings; use Net::Netmask; # our owners and their ranges my @blocks = ( [ 'bob', '192.168.1.0/24' ], [ 'nancy', '192.168.1.12' ], [ 'ralph', '192.168.2.0/255.255.255.0' ], [ 'bob', '192.168.3.0/24' ], [ 'NOBODY', '0.0.0.0/0' ], ); # populate the table with tagged blocks for my $block (@blocks) { my ($owner, $range) = @$block; my $nb = Net::Netmask->new2($range); $nb->tag('owner', $owner); $nb->storeNetblock(); }; # do the lookup. while (my $ip = <DATA>) { chomp $ip; my $block = findNetblock($ip); print "$ip belongs to ", $block->tag('owner'), "\n"; } __DATA__ 192.168.1.45 192.168.1.12 192.168.2.4 192.168.3.33 192.168.4.12
Output:
$ ./net_netmask.pl 192.168.1.45 belongs to bob 192.168.1.12 belongs to nancy 192.168.2.4 belongs to ralph 192.168.3.33 belongs to bob 192.168.4.12 belongs to NOBODY
This works rather well unless you're trying to grok the full internet route tables or such. (Somewhere there's a XS module that implements the routing table from BSD if you need really fast/big).

In reply to Re: Quickly determine which IP range an IP belongs to. by Anonymous Monk
in thread Quickly determine which IP range an IP belongs to. by punch_card_don

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.