Wednesday, November 7, 2012

Finding Unused IPs

I recently had a need to fit a new host onto a crowded network, without well documented address assignments.  This led me to several obvious answers, all of which required reading long lists of IP addresses while looking for gaps here and there.  Since reading through DNS zone files, or filtering Nmap ping sweep output didn't sound like much fun, I threw this little guy together.

#!/usr/bin/perl
#############################
## ipchecker.pl            ##
## (c)2012 Peter H. Ezetta ##
#############################


use strict;
use warnings;
use 5.010;

my @results;

foreach (`nmap -sP -v 192.168.0.*`) {
    chomp;
    push( @results, $_ ) if (/^Host/);
}

foreach (@results) {
    say if (/down/);
}

Change the address in the foreach loop to match the network you're scanning, and Nmap will run a ping scan like normal, with a nice little Perl wrapper to only give you the hosts that are down, instead of  up.

No comments:

Post a Comment