From 39588958ee319c2cf6e3fa70963ba03cfe55812d Mon Sep 17 00:00:00 2001 From: Stephen L Johnson Date: Fri, 15 Sep 2000 17:17:08 +0000 Subject: [PATCH] added module into CVS --- src/lib/Spong/Network/plugins/check_telnet | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/lib/Spong/Network/plugins/check_telnet diff --git a/src/lib/Spong/Network/plugins/check_telnet b/src/lib/Spong/Network/plugins/check_telnet new file mode 100644 index 0000000..c276402 --- /dev/null +++ b/src/lib/Spong/Network/plugins/check_telnet @@ -0,0 +1,53 @@ +# check_telnet - v 1.0 May 18, 2000 - scarpe01@tufts.edu + +# Register the routine with the plugins registry +$PLUGINS{'telnet'} = \&check_telnet; + + +# We are checking the telnet server here. There are no real error codes +# or anything...just see if its open and we can get a login prompt.... + +eval "require Net::Telnet;"; + +sub check_telnet { + my ($host) = @_; + # Find the list of ports to check + my @ports = $HOSTS{$host}->{'telnet_ports'} || + $HOSTS_DEFAULTS{'telnet_ports'} || + (23); + # Append mandatory ports from the 'ALL' host + @ports = ( @ports, @{$HOSTS_ALL{'telnet_ports'}} ); + my ($color, $summary, $message) = ("green", "", ""); + + foreach $port (@ports) { + my $con = new Net::Telnet; + my $ok = $con->open(Host=> $host, Port => $port); + if (! $ok) { + $color = "red"; + $message .= "$host:$port -\n" . $con->errmsg() . "\n"; + next; + } + + $con->print("\n\n"); + my @data = $con->getlines((Timeout => 6)); + if (@data) { + $message .= "$host:$port -\n@data\n"; + } else { + $color = "yellow" unless $color eq "red"; + $message .= "$host:$port -\n Timed out reading data\n"; + } + $con->close(); + } + + if ($color eq "green") { + $summary = "Telnet test(s) OK"; + } else { + $summary = "Telnet Not OK"; + } + + &debug("telnet - $host - $color, $summary"); + return( $color, $summary, $message); +} + +1; # Leave me here + -- 2.30.2