0

I have this little bit of code in a while statement while(<PS>) and it will not execute and read the output of the open(PS,"blabla") code.

How do I resolve this?

#!/usr/bin/env perl
#

my $IPendnum = 1;
my $IPrange = 0;
my $START = 1;

while ($START == 1) {
        print "Pinging IP : 192.168." . $IPrange . "." . $IPendnum . "\n";
        open (PS, "fping 192.168." . $IPrange . "." . $IPendnum);
        while(<PS>) {
                chop ($_);
                if (/is alive/) {
                        print "The following IP : 192.168." . $IPrange . "." . $IPendnum . " is online! \n";
                } else {
                        print "The following IP : 192.168." . $IPrange . "." . $IPendnum . " is currently offline! \n";
                }
        }

        if ($IPendnum >= 255) {
                $IPrange += 1;
                $IPendnum = 1;
        } else {
                $IPendnum += 1;
        }
        print "Moving to the next IP address \n";
        sleep(1);
}
DavidPostill
  • 156,873

1 Answers1

1

You are trying to open a file. You run a command like this:

open (PS, "-|", "fping 192.168.$IPrange.$IPendnum");
hymie
  • 1,266