mirror of
https://github.com/wfjm/w11.git
synced 2026-01-14 07:50:08 +00:00
55 lines
1.4 KiB
Perl
Executable File
55 lines
1.4 KiB
Perl
Executable File
#!/usr/bin/perl -w
|
|
# $Id: telnet_wrapper 314 2010-07-09 17:38:41Z mueller $
|
|
#
|
|
# Copyright 2009- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
|
|
#
|
|
# 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:
|
|
# 2009-11-07 246 1.0 Initial version
|
|
#
|
|
|
|
use 5.005; # require Perl 5.005 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 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;
|
|
}
|
|
}
|