###############################################
jrhmpt01:/root/sbin# cat a3.pl
use IO::Socket;
$server='121.40.167.35';
$port=8081;
$sock = IO::Socket::INET->new(PeerAddr => $server,
PeerPort => $port,
Proto => 'tcp') ;
print "$sock is $sock
";
jrhmpt01:/root/sbin# perl a3.pl
$sock is IO::Socket::INET=GLOB(0x1a9d0d0)
jrhmpt01:/root/sbin# cat a3.pl
use IO::Socket;
$server='121.40.167.35';
$port=8082;
$sock = IO::Socket::INET->new(PeerAddr => $server,
PeerPort => $port,
Proto => 'tcp') ;
print "$sock is $sock
";
jrhmpt01:/root/sbin# perl a3.pl
$sock is
#######################################################
jrhmpt01:/root/sbin# cat check_port.pl
use IO::Socket;
##监控8081
sub check_server_alive {
( $server, $port ) = @_;
$sock = IO::Socket::INET->new(PeerAddr => $server,
PeerPort => $port,
Proto => 'tcp');
if (defined($sock)){return 0}else{return 100};
};
$server='121.40.167.35';
$port=8081;
$result =check_server_alive($server,$port);
print "$result is $result
";
jrhmpt01:/root/sbin# perl check_port.pl
$result is 0
jrhmpt01:/root/sbin# cat check_port.pl
use IO::Socket;
##监控8081
sub check_server_alive {
( $server, $port ) = @_;
$sock = IO::Socket::INET->new(PeerAddr => $server,
PeerPort => $port,
Proto => 'tcp');
if (defined($sock)){return 0}else{return 100};
};
$server='121.40.167.35';
$port=8082;
$result =check_server_alive($server,$port);
print "$result is $result
";
jrhmpt01:/root/sbin# perl check_port.pl
$result is 100