#!/usr/bin/perl
#
use strict;
use IO::Socket;
my @servers;
$servers[0]=[‘180.153.100.93’,2222];
$servers[1]=[‘180.153.100.93’,22];
$servers[2]=[‘180.153.100.93’,80];
my $i=0;
my $interval=3;
my $count=int(60/$interval);
while($i < $count){
foreach (@servers){
if(fetch_server_status(@$_)){
print $$_[0] . ‘:’ . $$_[1] .”ok\n”;
}else{
print $$_[0] . ‘:’ . $$_[1] .”bad\n”;
}
}
$i++;
sleep $interval;
}
sub fetch_server_status(){
my($ip,$port)=@_;
my $socket=IO::Socket::INET->new(
PeerAddr=> $ip,
PeerPort=> $port,
Timeout=> 1,
);
if(!$socket){
return 0;
}else{
return 1;
}
$socket->close;
}
© 版权声明
文章版权归作者所有,未经允许请勿转载。