Re: How do you telnet from 1 host to another using Telnet Module
- From: John Mason Jr <notvalid@xxxxxxxxxxxxxxx>
- Date: Fri, 30 Dec 2005 17:13:58 -0500
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;
.- References:
- How do you telnet from 1 host to another using Telnet Module
- From: mark1 . thompson45
- Re: How do you telnet from 1 host to another using Telnet Module
- From: James E Keenan
- Re: How do you telnet from 1 host to another using Telnet Module
- From: John Mason Jr
- Re: How do you telnet from 1 host to another using Telnet Module
- From: mark1 . thompson45
- How do you telnet from 1 host to another using Telnet Module
- Prev by Date: Re: How do you telnet from 1 host to another using Telnet Module
- Next by Date: CPAN shell says "Out of memory!"
- Previous by thread: Re: How do you telnet from 1 host to another using Telnet Module
- Next by thread: Dave Roth's site (Win32::AdminMisc, Win32::ODBC, etc.) not available.
- Index(es):
Relevant Pages
|
|