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



mark1.thompson45@xxxxxxxxxxxxxx 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@xxxxxxxxxxxxxx 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;
.



Relevant Pages

  • Re: Help with Expect Script
    ... I want the script to ping the ... > host to see if it's alive first before it telnets into it. ... I already know how to telnet to the host, ...
    (freebsd-questions)
  • Re: Help with Expect
    ... > I need some help with an expect script I'm trying to write. ... If the host responds to pings telnet into it. ... You can ping a host and test whether it was successful from a shell ...
    (freebsd-questions)
  • Re: Help with Expect
    ... I need to this be in an expect script because I will be entering ... If the host responds to pings telnet into it. ...
    (freebsd-questions)
  • Expect, telnet, frozen console.
    ... telnet into remote host, provide username/password, surrender control to ... This script will eventually be tied into /etc/inittab so that it ... app called 'loe' which presents a login screen in 80x24 ASCII a la ...
    (comp.lang.tcl)
  • Re: rlogin
    ... login the server using telnet, rsh, rlogin and also ssh. ... Telnet does not provide any protection. ... We have only 1 host system. ...
    (comp.unix.aix)