use strict; use warnings; use Array::IntSpan qw( ); use Math::BigInt qw( ); use Socket qw( AF_INET6 inet_pton ); sub ip6_to_num { return Math::BigInt->new( '0x' . unpack 'H32', inet_pton AF_INET6, $_[0] ); } my $span = Array::IntSpan->new( [ ip6_to_num('2001:0db8:85a3:0000:0000:0000:0000:0000'), ip6_to_num('2001:0db8:85a3:ffff:ffff:ffff:ffff:ffff'), 'Some Network', ] ); for my $addr (qw( 2001:db8:85a3::8a2e:370:7334 2001:dc8:85a3::8a2e:370:7334 )) { my $network = $span->lookup(ip6_to_num($addr)); printf("Address %s is %s\n", $addr, $network ? "present in $network" : 'absent', ); }
Address 2001:db8:85a3::8a2e:370:7334 is present in Some Network Address 2001:dc8:85a3::8a2e:370:7334 is absent
In reply to Re^2: Storing and searching sets of IP address ranges
by ikegami
in thread Storing and searching sets of IP address ranges
by acferen
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |