Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- ## Scan a 24bit CIDR network for pingable hosts
- use 5.10.0;
- use Net::Ping;
- my $ipRange = shift or die "Usage: pingrng <IP Address>\n";
- my @ipSubset = split /\./, $ipRange;
- #Verify IP Address range
- for (@ipSubset) {
- die "Invalid IP adress - $ipRange\n"
- if not $_ || ($_ < 0 || $_ > 255);
- }
- my $kidpid;
- for (1 .. 254) {
- my $currIP = join ".", (@ipSubset[0,1,2], $_);
- die "Could not fork()\n" unless defined ($kidpid = fork);
- if ($kidpid) {
- #Parent process
- waitpid($kidpid, 0);
- }
- else {
- #Child process
- my $pingConn = Net::Ping->new(); #TCP
- say "$currIP up" if $pingConn->ping($currIP);
- $pingConn->close();
- #Nothing else to do
- exit;
- }
- }
- say "Finished scanning $ipRange/24";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement