2 |
rodolico |
1 |
#! /usr/bin/env perl
|
|
|
2 |
|
|
|
3 |
# Simple script to ping every IP in a /24 subnet, from .1 to .254
|
|
|
4 |
# The only purpose for this is to refresh an arp table before running
|
|
|
5 |
# the mapSwitchPorts scripts
|
|
|
6 |
#
|
|
|
7 |
# it limits the max wait for an IP to respond to 1 second, so in theory
|
|
|
8 |
# it could take 252 seconds to run (ie, a little over 4 minutes)
|
|
|
9 |
# at the end, it dumps the arp table
|
|
|
10 |
|
|
|
11 |
use strict;
|
|
|
12 |
use warnings;
|
|
|
13 |
|
|
|
14 |
my $firstIP = 1;
|
|
|
15 |
my $lastIP = 20;
|
|
|
16 |
|
|
|
17 |
my $subnet = shift;
|
|
|
18 |
die "Syntax: pingall.pl subnet.to.scan\nExample: pingall.pl 192.168.145.0\n" unless $subnet;
|
|
|
19 |
|
|
|
20 |
# Change subnet to only be the first three octets
|
|
|
21 |
my @octets = split( '\.', $subnet );
|
|
|
22 |
$subnet = join( '.', @octets[0,1,2] );
|
|
|
23 |
|
|
|
24 |
for ( my $i = $firstIP; $i <= $lastIP; $i++ ) {
|
|
|
25 |
`ping -w1 -c1 -q $subnet.$i 2>&1 >/dev/null`;
|
|
|
26 |
#print "ping -w1 -c1 -q $subnet.$i 2&>1 >/dev/null\n";
|
|
|
27 |
#print "\r$i" unless $i % 10;
|
|
|
28 |
}
|
|
|
29 |
|
|
|
30 |
#print `arp -n`;
|
|
|
31 |
|
|
|
32 |
1;
|