#!/usr/bin/perl -w # $Id: telnet_wrapper 832 2016-12-28 09:49:47Z mueller $ # # Copyright 2009-2013 by Walter F.J. Mueller # # This program is free software; you may redistribute and/or modify it under # the terms of the GNU General Public License as published by the Free # Software Foundation, either version 2, 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 complete details. # # Revision History: # Date Rev Vers Comment # 2009-11-07 246 1.0 Initial version # use 5.14.0; # require Perl 5.14 or higher use strict; # require strict checking if (scalar(@ARGV) != 2) { print STDERR "usage: telnet_wrapper host port\n"; exit 1; } my $host = $ARGV[0]; my $port = $ARGV[1]; print "$host $port\n"; my $telnet = `which telnet`; chomp $telnet; while(1) { my $rc = system $telnet, $host, $port; if ($rc != 0) { print STDERR "telnet failed with rc=$rc\n"; } print "enter q or <^D> to quit, otherwise hit to reconnect: "; my $buf; my $nc = read STDIN, $buf, 1; if (not defined $nc) { print "\n"; exit 1; } if ($nc == 0) { print "\n"; exit 0; } if ($buf eq "q") { exit 0; } }