in reply to Re^2: IP Iterator
in thread IP Iterator

If you don't want to use an "extra module" then you can do it like this:

#!/usr/bin/perl use warnings; use strict; use Net::Ping; if ( @ARGV != 2 ) { print "ipiterator <startip> <endip> \n"; exit 0; } my ( $start, $end ) = map unpack( 'N', pack 'CCCC', split /\./ ), @ARGV; for my $count ( $start .. $end ) { my $ip = join '.', unpack 'CCCC', pack 'N', $count; print "checking ip: $ip"; my $p = Net::Ping->new( 'icmp', 2 ); print ' ping success' if $p->ping( $ip ); $p->close(); print "\n"; }

Replies are listed 'Best First'.
Re^4: IP Iterator
by ikegami (Patriarch) on Apr 17, 2008 at 22:29 UTC

    for my $count ( $start .. $end ) won't work for IP address ≥ to 128.0.0.0 on a 32-bit system. Use a C-style for loop instead.

    This was already mentioned (along with the methodology you used) in my earlier node.

Re^4: IP Iterator
by camlet (Novice) on Apr 18, 2008 at 00:46 UTC
    its the a,b,c network class increments are show below
    ./ipiterator.pl 17 2.29.140.250 172.29.141.4 checking ip: 172.29.140.250 ping success checking ip: 172.29.140.251 ping success checking ip: 172.29.140.252 checking ip: 172.29.140.253 ping success checking ip: 172.29.140.254 checking ip: 172.29.<b>140</b>.255 checking ip: 172.29.<b>141</b>.0 checking ip: 172.29.141.1 checking ip: 172.29.141.2 ./ipcheck.pl 172.254.254.254 173.0.0.4 checking ip: 172.254.254.254 checking ip: 172.<b>254</b>.254.255 checking ip: <b>173</b>.0.0.0 checking ip: 173.0.0.1 ping success checking ip: 173.0.0.2 ping success checking ip: 173.0.0.3