#!/usr/bin/perl
#
# Use tcp_scan to try to connect to the telnet
# port on a bunch of hosts, and look for a "login"
# prompt. For use with "mon".
#
# Arguments are "host [host...]"
#
# Jim Trocki, trockij@transmeta.com
#
# $Id: telnet.monitor,v 1.4 1998/01/18 17:40:24 trockij Exp $
#
#    Copyright (C) 1998, Jim Trocki
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
use Getopt::Std;
getopts ("p:t:");
$PORT = $opt_p || 23;
#
# this timeout might need some tuning.
#
$TIMEOUT = $opt_t || 15;

@failures = ();

foreach $host (@ARGV) {
    $output = `tcp_scan -w $TIMEOUT -t $TIMEOUT -b $host $PORT`;
    chomp $output;
    if ($output !~ /login:/) {
	push (@failures, "$host");
    }
}

if (@failures == 0) {
    exit 0;
}
print "@failures\n";
exit 1;
