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?
In reply to Code Review: Checking open ports. by Chady
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |