Chady has asked for the wisdom of the Perl Monks concerning the following question:
Dear monks,
I'm writing a small utility to monitor certain services on a dozen servers or so. I shouldn't have access on these servers, so I decided for the POP, SMTP and FTP monitoring to just check if their ports are open, since I wouldn't have access to check a logon.
I wrote this snippet:
sub checkports { my $sock; my ($pop, $smtp, $ftp) = @_; DEBUG && print "Checking ports : "; my %ports = ( 110 => $pop, 25 => $smtp, 21 => $ftp ); for my $port (keys %ports) { DEBUG && print "[$port] "; $sock = new IO::Socket::INET(PeerAddr => $ports{$port}, PeerPo +rt => $port, Proto => 'tcp', Timeout=>10); if ($sock) { $client->{"PORT$port"} = 'U'; close $sock; } else { $client->{"PORT$port"} = 'D'; } } DEBUG && print " done.\n"; }
Since I have a fairly small knowledge in networking, I was wondering if this approach is reasonable; Is there another way to check if the services are up without having to get a username/password and try a real login?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Code Review: Checking open ports.
by ozone (Friar) on Jun 09, 2003 at 08:58 UTC | |
by waswas-fng (Curate) on Jun 09, 2003 at 11:30 UTC | |
by naChoZ (Curate) on Jun 09, 2003 at 12:15 UTC | |
by fsn (Friar) on Jun 09, 2003 at 11:41 UTC | |
|
Re: Code Review: Checking open ports.
by hardburn (Abbot) on Jun 09, 2003 at 13:59 UTC |