Skip to main content

check_telnet_response.pl

#!/usr/bin/perl
 
#
# checked Telnet-Port unserer Portmaster auf korrekte Response
#
# 2005 by OV
#
 
use IO::Socket;
 
my $line = "";
 
my $RemoteHost = $ARGV[0];
my $RemotePort = $ARGV[1];
my $CheckString = $ARGV[2];
 
local $SIG{ALRM} = sub { print "CRITICAL - Timeout waiting for correct response\n"; exit 2; };
alarm 6;
 
# print "Host " . $RemoteHost . " Port " . $RemotePort . " String " . $CheckString . "\n";
 
my $remote = IO::Socket::INET->new(
        Proto => "tcp",
        PeerAddr => $RemoteHost,
        PeerPort => $RemotePort,
        Timeout => 10,)
or die "CRITICAL - cannot connect to Port $RemotePort at $RemoteHost";
 
while (($line = <$remote>) && !($line =~ /$CheckString/)) {
        # dummy-schleife solange durchlaufen bis der checkstring auftaucht
}
 
print "OK - Response received\n";
exit 0;