Discussion:
redefining Net::Telnet "escape" character
Joe Mecklin
2005-02-25 13:44:18 UTC
Permalink
i sent this to the comp.lang.perl.modules newsgroup as the
documentation suggests and got no response at all, so i thought i'd
see if anyone here may be able to help.

i'm using net::telnet to connect to a remote script (rather than a
login). the script internally uses "^]" to step back through itself,
conflicting with the default escape telnet character. this wouldn't
be a problem per se except that the login to the system uses securid
(requiring manual login each time), and once i connect i need to step
through verifying several hundred auxiliary systems; being forced to
manually login for each new test would negate the benefits of a
script.

i had the idea of, once connecting, dropping back to telnet and doing
a "set escape ^[" but then realized net::telnet may not drop back to a
telnet prompt as the telnet command would (no i haven't verified this
for sure yet because i had my "epiphany" just as i was leaving work
for the day, and i've been forced to take the rest of the week off for
personal reasons).

question: what is one/the way to redefine the net::telnet escape
character from ^] to another ^[ (or anything else?)

tia,
joe
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>
m***@optonline.net
2005-02-25 17:13:41 UTC
Permalink
Joe,
Try turning binmod on. If it fails post some code and a bit more od a description of what you are trying to do.
hth,
Mark G.

----- Original Message -----
From: Joe Mecklin <***@gmail.com>
Date: Friday, February 25, 2005 8:44 am
Subject: redefining Net::Telnet "escape" character
Post by Joe Mecklin
i sent this to the comp.lang.perl.modules newsgroup as the
documentation suggests and got no response at all, so i thought i'd
see if anyone here may be able to help.
i'm using net::telnet to connect to a remote script (rather than a
login). the script internally uses "^]" to step back through itself,
conflicting with the default escape telnet character. this wouldn't
be a problem per se except that the login to the system uses securid
(requiring manual login each time), and once i connect i need to step
through verifying several hundred auxiliary systems; being forced to
manually login for each new test would negate the benefits of a
script.
i had the idea of, once connecting, dropping back to telnet and doing
a "set escape ^[" but then realized net::telnet may not drop back
to a
telnet prompt as the telnet command would (no i haven't verified this
for sure yet because i had my "epiphany" just as i was leaving work
for the day, and i've been forced to take the rest of the week off for
personal reasons).
question: what is one/the way to redefine the net::telnet escape
character from ^] to another ^[ (or anything else?)
tia,
joe
--
<http://learn.perl.org/> <http://learn.perl.org/first-response>
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>
Joe Mecklin
2005-02-25 23:28:42 UTC
Permalink
i'll try it when i get back to work, though i don't see how binmode
will tell me what net::telnet command i need to use to redefine a
character sequence, or what external command i'll need to call to
accomplish that. thanks for the suggestion, though.
Post by m***@optonline.net
Joe,
Try turning binmod on. If it fails post some code and a bit more od a description of what you are trying to do.
hth,
Mark G.
----- Original Message -----
Date: Friday, February 25, 2005 8:44 am
Subject: redefining Net::Telnet "escape" character
Post by Joe Mecklin
i sent this to the comp.lang.perl.modules newsgroup as the
documentation suggests and got no response at all, so i thought i'd
see if anyone here may be able to help.
i'm using net::telnet to connect to a remote script (rather than a
login). the script internally uses "^]" to step back through itself,
conflicting with the default escape telnet character. this wouldn't
be a problem per se except that the login to the system uses securid
(requiring manual login each time), and once i connect i need to step
through verifying several hundred auxiliary systems; being forced to
manually login for each new test would negate the benefits of a
script.
i had the idea of, once connecting, dropping back to telnet and doing
a "set escape ^[" but then realized net::telnet may not drop back
to a
telnet prompt as the telnet command would (no i haven't verified this
for sure yet because i had my "epiphany" just as i was leaving work
for the day, and i've been forced to take the rest of the week off for
personal reasons).
question: what is one/the way to redefine the net::telnet escape
character from ^] to another ^[ (or anything else?)
tia,
joe
--
<http://learn.perl.org/> <http://learn.perl.org/first-response>
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>
Joe Mecklin
2005-02-28 13:34:45 UTC
Permalink
ok, per the instructions, binmode only converts CR LF to \n, which is
not what i'm looking for.

here is a condensed version of the script:

###############

#!/usr/bin/perl

use ASI::WebDB;
use Term::ReadKey;
use Net::Telnet ();

my $login = "";
my $securid = "";

print "UID: ";
chomp($login = <>);
ReadMode noecho;
print "SECURID: ";
chomp($securid = <>);
ReadMode restore;

$t = new Net::Telnet (Timeout => 10);

$t->open("x.x.x.x");

print "\nlogging in to system";
&login_system;


sub login_system
{
my ($prematch, $match) = $t->waitfor(String => "login:", Errmode => 'return');
print "$prematch $match\n\n";
print "\nchanging \"escape\" character";
print "\n";
$t->put("^]");
($prematch, $match) = $t->waitfor(String => "telnet", Errmode => 'return');
print "$prematch $match\n\n";
print "\nback in telnet";
print "\n";
$t->print("set escape ^[");
$t->waitfor(String => "escape character is '^['.");
$t->print ("");
$t->waitfor(String => "login:", Errmode => 'return');
print "\nEntering stoak account login";
$t->print("$login");

$t->waitfor(String => "PASSCODE:", Errmode => 'return');
print "\nEntering SECURID PASSCODE";
$t->print("$securid");
}

##############

i get "pattern match timed-out at ./script-name line 102" which is

$t->waitfor(String => "escape character is '^['.");

so escaping back to the normal telnet prompt to change the escape
character doesn't work. a normal telnet "escape" character is ^] ...
i need to know how to change that from ^] to ^[ (or ^A or whatever)
within net::telnet

again, tia for any help
joe
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>
Wiggins d'Anconia
2005-02-28 15:05:32 UTC
Permalink
Post by Joe Mecklin
ok, per the instructions, binmode only converts CR LF to \n, which is
not what i'm looking for.
Out of curiousity isn't the escape character used for client side
handling? In this case why would you need to worry about the escape
character, as you can drop to a subshell from within Perl, and since
this is talking directly to a telnet session it doesn't really make
since to drop to a subshell, as that subshell would be your Perl script???
Post by Joe Mecklin
###############
#!/usr/bin/perl
use ASI::WebDB;
use Term::ReadKey;
use Net::Telnet ();
my $login = "";
my $securid = "";
print "UID: ";
chomp($login = <>);
ReadMode noecho;
print "SECURID: ";
chomp($securid = <>);
ReadMode restore;
$t = new Net::Telnet (Timeout => 10);
$t->open("x.x.x.x");
print "\nlogging in to system";
&login_system;
sub login_system
{
my ($prematch, $match) = $t->waitfor(String => "login:", Errmode => 'return');
print "$prematch $match\n\n";
print "\nchanging \"escape\" character";
print "\n";
$t->put("^]");
My first guess is that the above is sending '^' and then ']' instead of
the control charactert that you want. So you should convert the above to
the hex representation of the character so Perl knows what you are
really talking about, or use the Ctrl+V Ctrl+] sequence.
Post by Joe Mecklin
($prematch, $match) = $t->waitfor(String => "telnet", Errmode => 'return');
print "$prematch $match\n\n";
print "\nback in telnet";
print "\n";
$t->print("set escape ^[");
$t->waitfor(String => "escape character is '^['.");
$t->print ("");
$t->waitfor(String => "login:", Errmode => 'return');
print "\nEntering stoak account login";
$t->print("$login");
$t->waitfor(String => "PASSCODE:", Errmode => 'return');
print "\nEntering SECURID PASSCODE";
$t->print("$securid");
}
##############
i get "pattern match timed-out at ./script-name line 102" which is
$t->waitfor(String => "escape character is '^['.");
so escaping back to the normal telnet prompt to change the escape
character doesn't work. a normal telnet "escape" character is ^] ...
i need to know how to change that from ^] to ^[ (or ^A or whatever)
within net::telnet
again, tia for any help
joe
Did you turn on the debugging switch?

http://danconia.org
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>
Joe Mecklin
2005-02-28 15:41:11 UTC
Permalink
On Mon, 28 Feb 2005 10:05:32 -0500, Wiggins d'Anconia
Post by Wiggins d'Anconia
Post by Joe Mecklin
ok, per the instructions, binmode only converts CR LF to \n, which is
not what i'm looking for.
Out of curiousity isn't the escape character used for client side
handling? In this case why would you need to worry about the escape
character, as you can drop to a subshell from within Perl, and since
this is talking directly to a telnet session it doesn't really make
since to drop to a subshell, as that subshell would be your Perl script???
my apologies, apparently i'm leaving out too many details to be
clearly understood...

net::telnet is building a telnet session (with an escape character of
^]) to a solaris server.

the solaris server requires a login with SECURID, requiring a manual
(unprogrammable) login for every connection.

once connected, i am immediately entered into a menu script which
allows selection of multiple auxiliary systems; each of these systems
is a piece of Cisco hardware which also has auxiliary systems
connected to them.

each Cisco system has a restricted shell with a minimal telnet
command. this telnet command only allows ip and port for arguments;
it does not allow the user to change its internal escape character,
which is also the default ^].

once i connect to each of these systems for testing and want to drop
connection, using the default ^] drops me all the way back to my local
prompt, requiring another manual connection to the frontend solaris
server. not being able to maintain connection within the solaris
server negates the usefulness of the script completely.

the fact that ^] is the recognized escape character for every
connection i make in the sequence is why i need to redefine it in my
initial connection, since i am unable to redefine it in my subsequent
connections

.
.
.
Post by Wiggins d'Anconia
Post by Joe Mecklin
sub login_system
{
my ($prematch, $match) = $t->waitfor(String => "login:", Errmode => 'return');
print "$prematch $match\n\n";
print "\nchanging \"escape\" character";
print "\n";
$t->put("^]");
My first guess is that the above is sending '^' and then ']' instead of
the control charactert that you want. So you should convert the above to
the hex representation of the character so Perl knows what you are
really talking about, or use the Ctrl+V Ctrl+] sequence.
i do use Ctrl+V Ctrl+] in my code to enter the control sequence, but
that actual sequence doesn't display properly in the email so i
converted it to an ascii sequence for reading purposes.

this is a modified version of a script that works fine; the
differences are in the destination systems, which are radically
different in responses and connection sequences. on the working
script i can modify ^] in the downstream telnet connections; as noted
above, on these systems that is not an option.

.
.
.
Post by Wiggins d'Anconia
Post by Joe Mecklin
so escaping back to the normal telnet prompt to change the escape
character doesn't work. a normal telnet "escape" character is ^] ...
i need to know how to change that from ^] to ^[ (or ^A or whatever)
within net::telnet
again, tia for any help
joe
Did you turn on the debugging switch?
http://danconia.org
i did not use debugging; the script works as far as it goes. i need
the proper external command or net::telnet function/sub call to modify
the default definition of the escape character so that the desired
character (^[ rather than ^]) is passed, and debug will not give me
that information.

thanks for the suggestions, though.
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>
Loading...