Kevin Pfeiffer wrote:
>
> In article <[EMAIL PROTECTED]>, John W. Krahn wrote:
>
> > Kevin Pfeiffer wrote:
> >>
> >> In article <[EMAIL PROTECTED]>, John W. Krahn wrote:
> >>
> >> > You need to convert the IP address to a 32 bit integer and back again.
> [...]
>
> >> (But this includes numbers such as 12.13.1.255 and 12.13.2.0 which are
> >> not in the sample pattern.)
> >
> > That depends. They could all be in the 8/5 address space. :-) I take
> > it that you are assuming a netmask of 255.255.255.0.
>
> Ah yes. My example then is actually wrong as my series simply counts to 254
> in each of the four quads. :-(
>
> Your follow-up solution has gone in my archive.
Don't be too quick with that. :-) I did some more testing and on
Perl 5.6.0 (I know I should upgrade) the range operator doesn't like
integers larger then 0x7FFFFFFF. So if you have a different version
of Perl you should test it with a wide range of IP addresses. It
does however work with a C style for loop.
use Socket;
my $netmask = 0xFFFFFF00; # 255.255.255.0
my $start_address = unpack 'N', inet_aton( '10.11.1.14' );
my $finish_address = unpack 'N', inet_aton( '12.13.2.3' );
for ( my $address = $start_address; $address <= $finish_address; ++$address ) {
next if ( $address & $netmask ) == $address or ( $address & ~$netmask ) ==
~$netmask;
print inet_ntoa( pack 'N', $address );
}
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]