CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Help with IO::Socket Service State check

 



flowon
New User

Dec 23, 2010, 5:57 AM

Post #1 of 1 (131 views)
Help with IO::Socket Service State check Can't Post

Hello,
I am newish to Perl and I found a script I think i can use to make what will be a very useful tool.

I have to monitor lots of remote services, so I wanted to create a webpage that will tell me if various services on other machines are up and running.

I have the following code, but all i get is a blank page when browse to it.

Can anyone tell me what might be going wrong?

Thanks!!


Code
 
#!/usr/local/bin/perl
use strict;
use IO::Socket;
use CGI qw(:standard);

my ($socket, $status);
# add services [ SERVICE NAME, IP ADDRESS, PORT ]
my @services = (
[ 'Service 1', 'localhost', '11150' ],
[ 'Service 2', 'localhost', '11111' ],
);
for my $i ( 0 .. $#services ) {
$status .= '<p>' . $services[$i][0]." is ";
$socket = IO::Socket::INET->new(
PeerAddr => $services[$i][1],
PeerPort => $services[$i][2],
Proto => 'tcp',
Type => SOCK_STREAM
);
if ($socket) {
$status .= "<b>UP</b>";
close($socket);
}
else {
$status .= "<b>DOWN</b>";
}
$status .= "</p>\n";
}

print header;
print start_htm1('Simple Service Status');
print hl('Simple Service Status') . "\n";
print $status;
print end_html;
exit;


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives