#! /usr/bin/env perl

# Simple script to ping every IP in a /24 subnet, from .1 to .254
# The only purpose for this is to refresh an arp table before running
# the mapSwitchPorts scripts
#
# it limits the max wait for an IP to respond to 1 second, so in theory
# it could take 252 seconds to run (ie, a little over 4 minutes)
# at the end, it dumps the arp table

use strict;
use warnings;

my $firstIP = 1;
my $lastIP = 20;

my $subnet = shift;
die "Syntax: pingall.pl subnet.to.scan\nExample: pingall.pl 192.168.145.0\n" unless $subnet;

# Change subnet to only be the first three octets
my @octets = split( '\.', $subnet );
$subnet = join( '.', @octets[0,1,2] );

for ( my $i = $firstIP; $i <= $lastIP; $i++ ) {
   `ping -w1 -c1 -q $subnet.$i 2>&1 >/dev/null`;
   #print "ping -w1 -c1 -q $subnet.$i 2&>1 >/dev/null\n";
   #print "\r$i" unless $i % 10;
}

#print `arp -n`;

1;
