Hi,
Background: I have two lists (L1 & L2) each containing an IP range and information about them(like country, state, zip..etc). List L1 is dynamically generated and it can contain more than 10 million records. L2 has 50-100 records. It is not necessary that these IP ranges are valid IP blocks. I have to iterate through the list L1 and check whether any of the IP range overlaps with any range in the L2 and if it overlaps, then substitute the information of L1 with L2 for matching range only(If the range does not overlaps completely then i need to split the range of L1). for example take a simple case; if current L1 record is 81.68.0.0 - 81.68.0.20, xyz and L2 record is 81.68.0.0 - 81.68.0.10, abc
L1 recors must be splitted into 81.68.0.0 - 81.68.0.10, abc and 81.68.0.11 - 81.68.0.20, xyz
I have gone through Net::IP module and found that it can used for testing overlap conditions but I am not sure about splitting ranges.
my $V_IP = new Net::IP('81.0.0.0 - 84.23.45.67') or die( Net::IP::Erro
+r() );
my $G_IP = new Net::IP('80.60.80.120 - 85.34.45.56') or die( Net::IP::
+Error() );
my $V_Match = $G_IP->overlaps($V_IP);
if (not defined($V_Match))
{
print "Problem with IP range\n";
} elsif ( $V_Match == $IP_IDENTICAL )
{
print $G_IP->print(), ' is identical with the range ', $V_
+IP->print(), "\n";
} elsif ( $V_Match == $IP_A_IN_B_OVERLAP )
{
print $V_IP->print(), ' contains the range ', $G_IP->print
+(), "\n";
} elsif ( $V_Match == $IP_B_IN_A_OVERLAP )
{
print $G_IP->print(), ' contains the range ', $V_IP->print
+(), "\n";
} elsif ( $V_Match == $IP_PARTIAL_OVERLAP )
{
print $G_IP->print(), ' partially overlaps with the range
+', $V_IP->print(),
"\n";
} elsif ( $V_Match == $IP_NO_OVERLAP )
{
print $V_IP->print(), ' doesnot overlap with ', $G_IP->pri
+nt(), "\n";
}
Could you please tell is there any module on CPAN that can do this thing?
Thanks
Kamesh
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.