Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

mutew

By: a guest on May 30th, 2009  |  syntax: Perl  |  size: 0.84 KB  |  hits: 62  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. ## Scan a 24bit CIDR network for pingable hosts
  5.  
  6. use 5.10.0;
  7. use Net::Ping;
  8.  
  9. my $ipRange  = shift or die "Usage: pingrng <IP Address>\n";
  10. my @ipSubset = split /\./, $ipRange;
  11.  
  12. #Verify IP Address range
  13. for (@ipSubset) {
  14.     die "Invalid IP adress - $ipRange\n"
  15.       if not $_ || ($_ < 0 || $_ > 255);
  16. }
  17.  
  18. my $kidpid;
  19. for (1 .. 254) {
  20.     my $currIP = join ".", (@ipSubset[0,1,2], $_);
  21.  
  22.     die "Could not fork()\n" unless defined ($kidpid = fork);
  23.     if ($kidpid) {
  24.         #Parent process
  25.         waitpid($kidpid, 0);
  26.     }
  27.     else {
  28.         #Child process
  29.         my $pingConn = Net::Ping->new();    #TCP
  30.         say "$currIP up" if $pingConn->ping($currIP);
  31.         $pingConn->close();
  32.  
  33.         #Nothing else to do
  34.         exit;
  35.     }
  36. }
  37.  
  38. say "Finished scanning $ipRange/24";