adambot has asked for the wisdom of the Perl Monks concerning the following question:
I'm hoping to not use any modules for children and just using built-in methods. Any help is appreciated.#!/usr/bin/perl use strict; use warnings; use Nmap::Parser; my @pids; my $max = 10; my $children = 0; my $net = shift(); if (!defined $net) { $net = "192.168.1"; } foreach my $count (1..10) { my $ipaddress; $ipaddress = $net . "." . $count; my $pid; if($children == $max) { $pid = wait(); $children--; } if(defined($pid = fork())) { if($pid) { #parent $children++; push @pids, $pid; } else { #child my $ssh = my $rdp = " "; my $np = new Nmap::Parser; my $nmap_path = "/usr/bin/nmap"; my $nmap_args = "-Pn -p 22,3389"; $np->parsescan($nmap_path, $nmap_args, $ipaddress); my $host = $np->get_host($ipaddress); my @ports = $host->tcp_ports('open'); foreach my $port (@ports) { if ($port == 22 ) { $ssh = "Y"; } if ($port == 3389 ) { $rdp = "Y" } } printf "%-15s %-4s %-4s\n", $ipaddress, $rdp, $ssh; exit; } } else { print "Error: failed to fork\n"; exit; } } for my $pid(@pids) { waitpid $pid, 0; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: console output invisible after script exit
by LanX (Saint) on Jan 15, 2022 at 19:04 UTC | |
by adambot (Acolyte) on Jan 15, 2022 at 20:44 UTC | |
by LanX (Saint) on Jan 16, 2022 at 02:53 UTC | |
by adambot (Acolyte) on Jan 16, 2022 at 18:10 UTC | |
|
Re: console output invisible after script exit
by tybalt89 (Monsignor) on Jan 15, 2022 at 21:23 UTC | |
by adambot (Acolyte) on Jan 16, 2022 at 02:33 UTC | |
|
Re: console output invisible after script exit
by etj (Priest) on Feb 27, 2022 at 20:14 UTC |