How do you telnet from 1 host to another using Telnet Module

How do you telnet from 1 host to another using Telnet Module

am 22.12.2005 01:15:24 von mark1.thompson45

Hello,
I need to know how you telnet from one host to another using
the net::telnet module. I can telnet to a single host OK but I need to
then jump from that host o a 2nd device, I cannot get this to work, I
merely start anothet telnet session from my host machine.

I am using:-

$script = new Net::Telnet (Timeout=>5, Errmode=>'return',
Prompt=>'/[\$?>:#\]] *$/');

I call this twice but on the 2nd call I would like to jump from the
server I previously telnetted to. I need to do this as some devices I
am trying to contact can only be accessed from a jumpstart server.


cheers, Mark.

Re: How do you telnet from 1 host to another using Telnet Module

am 28.12.2005 22:06:42 von mark1.thompson45

has anyone any idea's as to how I can achieve this, I guess what I am
saying is that I do not want to spawn a new telnet process for the
second telnet, I want to telnet from the host I previously telnetted
to.

cheers.

Re: How do you telnet from 1 host to another using Telnet Module

am 30.12.2005 17:07:07 von Jim Keenan

mark1.thompson45@btinternet.com wrote:
> Hello,
> I need to know how you telnet from one host to another using
> the net::telnet module. I can telnet to a single host OK but I need to
> then jump from that host o a 2nd device, I cannot get this to work, I
> merely start anothet telnet session from my host machine.
>
> I am using:-
>
> $script = new Net::Telnet (Timeout=>5, Errmode=>'return',
> Prompt=>'/[\$?>:#\]] *$/');
>
> I call this twice but on the 2nd call I would like to jump from the
> server I previously telnetted to. I need to do this as some devices I
> am trying to contact can only be accessed from a jumpstart server.
>
First: Are you certain that the second host will accept a telnet
request from the first host?

I do not have any direct experience with telnetting between two hosts,
but I recall that when I once tried to move files between two hosts
with Net::FTP, I could not do so, not because of any weakness in my
code or that module, but because the second host had restrictions
preventing me from doing so. Perhaps the same thing would be true for
telnetting.

Jim Keenan

Re: How do you telnet from 1 host to another using Telnet Module

am 30.12.2005 20:43:31 von John Mason Jr

James E Keenan wrote:
> mark1.thompson45@btinternet.com wrote:
>
>>Hello,
>> I need to know how you telnet from one host to another using
>>the net::telnet module. I can telnet to a single host OK but I need to
>>then jump from that host o a 2nd device, I cannot get this to work, I
>>merely start anothet telnet session from my host machine.
>>
>>I am using:-
>>
>>$script = new Net::Telnet (Timeout=>5, Errmode=>'return',
>>Prompt=>'/[\$?>:#\]] *$/');
>>
>>I call this twice but on the 2nd call I would like to jump from the
>>server I previously telnetted to. I need to do this as some devices I
>>am trying to contact can only be accessed from a jumpstart server.
>>
>
> First: Are you certain that the second host will accept a telnet
> request from the first host?
>
> I do not have any direct experience with telnetting between two hosts,
> but I recall that when I once tried to move files between two hosts
> with Net::FTP, I could not do so, not because of any weakness in my
> code or that module, but because the second host had restrictions
> preventing me from doing so. Perhaps the same thing would be true for
> telnetting.
>
> Jim Keenan
>


Turn on debugging/logging, most likely you need to modify the Prompt. At
least I did when I did the same thing.


ie;

$t->print("telnet $ip");
$t->waitfor('/Password:/');
$t->print($routerpasswd);
$t->waitfor($routers{$ip});


where $ip is ip address,
& $routers{$ip} is the Prompt


John

Re: How do you telnet from 1 host to another using Telnet Module

am 30.12.2005 22:01:35 von mark1.thompson45

It's not quite as simple as that but thanks for the reply, this may
help you more in understanding, from my limited experience with using
this module I have managed to successfully telnet from the host that my
script executes on to a remote host, I can do this ok using the
following:-

sub Telnet
{
$script = new Net::Telnet (Timeout=>5,
Errmode=>'return',Prompt=>'/[\$?>:#\]] *$/');
if (!($script->open($host)))
{
print "FAILED TO CONNECT\n";
} else {
sleep 1;
$script->waitfor('/login:/');
$script->print($uid);
etc
etc
}
}

If I now want to telnet from the host I have just telnetted to onto a
new host I come unstuck, here's why.

1. If I call the "Telnet" procedure again all I do is spawn another
telnet session from the host where my script executes from and not from
the previously telnettd to host. (I need to telnet from the previously
telnetted to host due to accessibility reasons).

2. If I disregard the "new NET::Telnet" line of the code when calling
the "Telnet" procedure the 2nd time I get an error about an "un-defined
value" which I think is because the telnet session has not been
initiated.

It is this problem that I cannot overcome.

cheers, Mark.


John Mason Jr wrote:
> James E Keenan wrote:
> > mark1.thompson45@btinternet.com wrote:
> >
> >>Hello,
> >> I need to know how you telnet from one host to another using
> >>the net::telnet module. I can telnet to a single host OK but I need to
> >>then jump from that host o a 2nd device, I cannot get this to work, I
> >>merely start anothet telnet session from my host machine.
> >>
> >>I am using:-
> >>
> >>$script = new Net::Telnet (Timeout=>5, Errmode=>'return',
> >>Prompt=>'/[\$?>:#\]] *$/');
> >>
> >>I call this twice but on the 2nd call I would like to jump from the
> >>server I previously telnetted to. I need to do this as some devices I
> >>am trying to contact can only be accessed from a jumpstart server.
> >>
> >
> > First: Are you certain that the second host will accept a telnet
> > request from the first host?
> >
> > I do not have any direct experience with telnetting between two hosts,
> > but I recall that when I once tried to move files between two hosts
> > with Net::FTP, I could not do so, not because of any weakness in my
> > code or that module, but because the second host had restrictions
> > preventing me from doing so. Perhaps the same thing would be true for
> > telnetting.
> >
> > Jim Keenan
> >
>
>
> Turn on debugging/logging, most likely you need to modify the Prompt. At
> least I did when I did the same thing.
>
>
> ie;
>
> $t->print("telnet $ip");
> $t->waitfor('/Password:/');
> $t->print($routerpasswd);
> $t->waitfor($routers{$ip});
>
>
> where $ip is ip address,
> & $routers{$ip} is the Prompt
>
>
> John

Re: How do you telnet from 1 host to another using Telnet Module

am 30.12.2005 23:13:58 von John Mason Jr

mark1.thompson45@btinternet.com wrote:
> It's not quite as simple as that but thanks for the reply, this may
> help you more in understanding, from my limited experience with using
> this module I have managed to successfully telnet from the host that my
> script executes on to a remote host, I can do this ok using the
> following:-
>
> sub Telnet
> {
> $script = new Net::Telnet (Timeout=>5,
> Errmode=>'return',Prompt=>'/[\$?>:#\]] *$/');
> if (!($script->open($host)))
> {
> print "FAILED TO CONNECT\n";
> } else {
> sleep 1;
> $script->waitfor('/login:/');
> $script->print($uid);
> etc
> etc
> }
> }
>
> If I now want to telnet from the host I have just telnetted to onto a
> new host I come unstuck, here's why.
>
> 1. If I call the "Telnet" procedure again all I do is spawn another
> telnet session from the host where my script executes from and not from
> the previously telnettd to host. (I need to telnet from the previously
> telnetted to host due to accessibility reasons).

Don't need to create a new Net::Telnet object just print then waitfor,
see snippet at the end of the message. If that doesn't point you in the
right direction I'll try to make a pl that will be able to run

>
> 2. If I disregard the "new NET::Telnet" line of the code when calling
> the "Telnet" procedure the 2nd time I get an error about an "un-defined
> value" which I think is because the telnet session has not been
> initiated.

can you check the values of the variables prior to the line giving you
the problem

>
> It is this problem that I cannot overcome.
>
> cheers, Mark.
>
>
> John Mason Jr wrote:
>
>>James E Keenan wrote:
>>
>>>mark1.thompson45@btinternet.com wrote:
>>>
>>>
>>>>Hello,
>>>> I need to know how you telnet from one host to another using
>>>>the net::telnet module. I can telnet to a single host OK but I need to
>>>>then jump from that host o a 2nd device, I cannot get this to work, I
>>>>merely start anothet telnet session from my host machine.
>>>>
>>>>I am using:-
>>>>
>>>>$script = new Net::Telnet (Timeout=>5, Errmode=>'return',
>>>>Prompt=>'/[\$?>:#\]] *$/');
>>>>
>>>>I call this twice but on the 2nd call I would like to jump from the
>>>>server I previously telnetted to. I need to do this as some devices I
>>>>am trying to contact can only be accessed from a jumpstart server.
>>>>
>>>
>>>First: Are you certain that the second host will accept a telnet
>>>request from the first host?
>>>
>>>I do not have any direct experience with telnetting between two hosts,
>>>but I recall that when I once tried to move files between two hosts
>>>with Net::FTP, I could not do so, not because of any weakness in my
>>>code or that module, but because the second host had restrictions
>>>preventing me from doing so. Perhaps the same thing would be true for
>>>telnetting.
>>>
>>>Jim Keenan
>>>
>>
>>
>>Turn on debugging/logging, most likely you need to modify the Prompt. At
>>least I did when I did the same thing.
>>
>>
>>ie;
>>
>> $t->print("telnet $ip");
>> $t->waitfor('/Password:/');
>> $t->print($routerpasswd);
>> $t->waitfor($routers{$ip});
>>
>>
>>where $ip is ip address,
>>& $routers{$ip} is the Prompt
>>
>>
>>John
>
>

Bigger example;

# log into first device

$t = new Net::Telnet (Timeout => 60);
# $t->input_log('debug_telnet.txt');
$t->open($host);
$t->login($username, $passwd);


# go check each device

foreach $ip ( sort { $routers{$a} cmp $routers{$b} } keys %routers){


$t->print("telnet $ip");
$t->waitfor('/Password:/');
$t->print($routerpasswd);
$t->waitfor($routers{$ip});

# Here I run some commands to check stats on routers (snipped)

$t->cmd("exit");

}

$t->close;