in reply to Nmap::Scanner breaks my while loop, I think

If calling ->scan calls die inside, you can use eval:
my $results; eval { $results = $scanner->scan("-v -sP $r[0]/$r[1]"); 1; } or warn " +Error catched: $@";

Replies are listed 'Best First'.
Re^2: Nmap::Scanner breaks my while loop, I think
by jantelar (Initiate) on Feb 14, 2012 at 06:39 UTC

    I really dont know what ->scan does upon errors. What I have tried is this:

    my $results; eval{ $results = $scanner->scan("-v -sP $r[0]/$r[1]"); }; print STDERR "Error catched: $@\n" if($@);

    But, this does not catch it. The while loop still ends right there.

      The while loop still ends right there.
      Are you sure? Is not it one line later? You should not call
      $results->get_host_list();
      if $results is empty.

        Yes, I am pretty sure. This code:

        print STDERR "\nNetwork $r[0], mask $r[1]\n"; my $scanner = new Nmap::Scanner; my $results; print STDERR "Start Scan\n"; eval{ $results = $scanner->scan("-v -sP $r[0]/$r[1]"); }; print STDERR "Error catched: $@\n" if($@); print STDERR "Scan complete\n";

        Yeilds this output:

        Network xx.xx.xx.xx, mask yy Start Scan Scan complete Network 10.8.165.160, mask 28 Start Scan <nmap-error> <pid="18142"/> <cmdline="'/usr/bin/nmap' -v -v -v -v -sP 10.8.165.160/28 -oX -"/> <nmap-err>RTTVAR has grown to over 2.3 seconds, decreasing to 2.0 </nmap-msg> </nmap-error>

        ie the two last prints are not executed