Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / Perl / Modules / June 2004



Tip: Looking for answers? Try searching our database.

Net::Telnet problem with MS Telnet Service

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
texbmex - 11 Jun 2004 16:42 GMT
Hello,

After reading the Net::Telnet documentation, examples, searching the
'Net, etc., I still do not completely understand the problem of
connecting to a "Microsoft Telnet Server".

I'm sure someone has already touched on this before.. If so, sorry about
the repeat.  Using a different Telnet server is not really an option at
this point in time.

The problems outlined in the module man pages under "Connecting to a
Remote MS-Windows Machine" seem to be clear, however, is it not at all
possible to capture the output? I must be missing something... or could
someone explain to me why it appears in the log but it cannot be captured?

Note: names/details have been change to protect the innocent. :o)

For example,

#!/usr/bin/perl
use strict;
use Net::Telnet;

my $username = "tester";
my $password = "pass_test";

my $t = new Net::Telnet(
               Timeout => 5,
               Host    => hostname,
               Errmode => "return"
            );

$t->login( $username, $password );

my $prompt = "_MYPROMPT_";
$t->prompt("/$prompt\$/");
$t->cmd("prompt = '$prompt'");
my $string = "java -version";
my @jver   = $t->cmd($string);
$t->close;

The @jver array contains no output after running the script.  If I use
input_log(), the following appears in the log:

###########
Welcome to Microsoft Telnet Service

login: tester
password:

*===============================================================
Welcome to Microsoft Telnet Server.
*===============================================================
C:\Documents and Settings\tester>prompt = '_MYPROMPT_'

'_MYPROMPT_'java -version
java version "1.4.2_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_03)
Java HotSpot(TM) Client VM (build 1.4.2_03, mixed mode)

'_MYPROMPT_'
###########

Using dump_log(), the following appears (snipped):

###########
< 0x00000: 57 65 6c 63  6f 6d 65 20  74 6f 20 4d  69 63 72 6f  Welcome
 to Micro
< 0x00010: 73 6f 66 74  20 54 65 6c  6e 65 74 20  53 65 72 76  soft
Telnet Serv
< 0x00020: 69 63 65 20  0d 0a 0a 0d  6c 6f 67 69  6e 3a 20     ice
....login:

<snip>

> 0x00000: 70 72 6f 6d  70 74 20 3d  20 27 5f 4d  59 50 52 4f  prompt =
> '_MYPRO
> 0x00010: 4d 50 54 5f  27 0d 0a                               MPT_'..

< 0x00000: 70 72 6f 6d  70 74 20 3d  20 27 5f 4d  59 50 52 4f  prompt =
'_MYPRO
< 0x00010: 4d 50 54 5f  27 0d 0a 0d  0a 27 5f 4d  59 50 52 4f
MPT_'....'_MYPRO
< 0x00020: 4d 50 54 5f  27                                     MPT_'

> 0x00000: 6a 61 76 61  20 2d 76 65  72 73 69 6f  6e 0d 0a     java -
> version..

< 0x00000: 6a 61 76 61  20 2d 76 65  72 73 69 6f  6e 0d 0a 6a  java -
version..j
< 0x00010: 61 76 61 20  76 65 72 73  69 6f 6e 20  22 31 2e 34  ava
version "1.4
< 0x00020: 2e 32 5f 30  34 2d 65 72  22 0d 0a 4a  61 76 61 28  .2_03"..Java(
< 0x00030: 54 4d 29 20  32 20 52 75  6e 74 69 6d  65 20 45 6e  TM) 2
Runtime En
< 0x00040: 76 69 72 6f  6e 6d 65 6e  74 2c 20 53  74 61 6e 64
vironment. Stand
< 0x00050: 61 72 64 20  45 64 69 74  69 6f 6e 20  28 62 75 69  ard
Edition (bui
< 0x00060: 6c 64 20 31  2e 34 2e 32  5f 30 34 2d  65 72 2d 32  ld 1.4.2_03
< 0x00070: 30 30 34 30  33 31 30 29  0d 0a 4a 61  76 61 20 48  )..Java H
< 0x00080: 6f 74 53 70  6f 74 28 54  4d 29 20 43  6c 69 65 6e
otSpot(TM) Clien
< 0x00090: 74 20 56 4d  20 28 62 75  69 6c 64 20  31 2e 34 2e  t VM
(build 1.4.
< 0x000a0: 32 5f 30 34  2d 65 72 2d  32 30 30 34  30 33 31 30  2_03
< 0x000b0: 2c 20 6d 69  78 65 64 20  6d 6f 64 65  29 0d 0a 0d  . mixed
mode)...
< 0x000c0: 0a 27 5f 4d  59 50 52 4f  4d 50 54 5f  27           .'_MYPROMPT_'
############

I used waitfor() and print() but it did not work either.  Is the syntax
below correct? According to the examples, it appears so and with a perl
expression of /java/ I would think that it should at least match something.

#########
my $matchop = '/java/';
(my $prematch, my $match) = $t->waitfor($matchop);
$t->print("java -version");
##########

Anyone have any ideas how I can capture this output? Or is it a hopeless
case over a MS Telnet Service?

Thanks for any help!
texbmex
Joe Smith - 23 Jun 2004 10:54 GMT
> my $prompt = "_MYPROMPT_";
> $t->prompt("/$prompt\$/");

That says you expect the prompt to be "_MYPROMPT_".

> $t->cmd("prompt = '$prompt'");

But that causes the prompt to be "'_MYPROMPT_'".
Have you tried that without the single quotes?
    -Joe
texbmex - 24 Jun 2004 17:52 GMT
Thanks! That did the trick... I knew I had to have been missing
something.  At least it was simple! :o)

texbmex

>> my $prompt = "_MYPROMPT_";
>> $t->prompt("/$prompt\$/");
[quoted text clipped - 6 lines]
> Have you tried that without the single quotes?
>     -Joe
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.