Help Required using NET::TELNET Module ??

M

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
telnet from that host to a 2nd machine, I cannot get this to work, I
merely start anothet telnet session (spawn a new telnet session) from
my host machine.

i.e.

this works:-
host machine -------> machine A

this does not:-
host machine -------> machine A -----------> machine B


I am using:-

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

I need to do this as some devices (machine B) I
am trying to contact can only be accessed from a jumpstart server
(machine A).


cheers, Mark.
 
G

Gratemyl

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
telnet from that host to a 2nd machine, I cannot get this to work, I
merely start anothet telnet session (spawn a new telnet session) from
my host machine.

i.e.

this works:-
host machine -------> machine A

this does not:-
host machine -------> machine A -----------> machine B


I am using:-

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

I need to do this as some devices (machine B) I
am trying to contact can only be accessed from a jumpstart server
(machine A).


cheers, Mark.

Please include some more (if not all) code, then better support can be
given. My understanding is that you would like to make a connection to
machine B, which originates from machine A. Though this is possible,
you will need to give more info, so we can help.

Yours,

Gratemyl
 
M

mark1.thompson45

you ae correct, I would like the connection to machine B to originate
from machine A and not from the machine where the script is executed
from. I have attached the code if it will help, it basically loops
through a list of machines executing the 'telnet' command:-

open (HOSTS, "D:\\Documents and Settings\\801825642\\My
Documents\\tom1.txt");
while (my $line = <HOSTS>)
{
if ($line =~ m/--/)
{
#print "Comment Line Only\n";
} else {
@Data = split(":", $line);
$uid = $Data[2];
$pwd = $Data[3];
chomp $Data[6];
## check if a jumpastart server is required
if ($Data[4] ne '')
{
$jump_host = $Data[4];
$uid = $Data[5];
$pwd = $Data[6];
jump_start();
} else {
$jump_host = $Data[1];
Telnet_To_Device();
}

}
}

close(HOSTS);
create_csv();
create_webpage();
exit 0;


sub Telnet_To_Device
{
if ($jump == 0)
{
#print "\n\nTELNET CONNECTION EXISTS\n\n";
$script = new Net::Telnet ( Timeout=>5, Errmode=>'return', Prompt =>
'/[\$?>:#\]] *$/');
} else {
$script = new Net::Telnet ( Timeout=>5, Errmode=>'return', Prompt
=> '/[\$?>:#\]] *$/');
}
#$script->dump_log(@Data[0]."debug.log");
#$script->input_log('STDERR');

if (!($script->open($jump_host))) {
print "FAILED TO CONNECT TO $Data[0]\n";
return;
} else {
#print "\n\n>>$uid<-->$pwd<<\n\n";
print "\n\n$Data[0]:$Data[4]\n";
if ($jump)
{
#print "DO NOT ADD TO HASH - AS ONLY JUMPSTART\n";
} else {
$Output{$Data[0]} = "$Data[1],$Data[0],";
}
sleep 1;
$script->waitfor('/login:/i');
$script->print($uid);
sleep 1;
$script->waitfor('/password:/i');
my ($Before,$After) = $script->print($pwd);
sleep 1;
#print "B=$Before <==> A=$After\n";

#----------> check password is correct <-----------#

my ($Before,$After) = $script->waitfor('/Do you/');
#print "B=$Before <--> A=$After\n";
#sleep 5;

if ($After =~ m/do you understand/i)
{
print "IN SECURITY...\n";
$script->print('Y');
if ($Data[2] =~ m/nsg/i)
{
print "IN NSG...\n";
sleep 0.5;
$script->waitfor('/Please hit/i');
#print "B=$Before <==> A=$After\n";
$script->print('\n'); # nsg accounts - carriage return
sleep 0.5;
$script->waitfor('/[\$?>:#\]] *$/');
#print "B=$Before <==> A=$After\n";
} else {
print "NOT NSG ACCOUNT...\n";
sleep 0.5;
my ($Before,$After) = $script->waitfor('/[\$#] $/');
#print "B=$Before <==> A=$After\n";
}

} else { # straight to box prompt
#sleep 2;
print "NO WARNING...\n";
my ($Before,$After) = $script->waitfor('/[\$?>:#\]] *$/');
#my ($Before,$After) = $script->waitfor('/[\$%#>)/');
#print "B=$Before <==> A=$After\n";
}

if ($jump)
{
#print "Going from TELNET to JUMP\n";
return;
} else {
omnihome();
uname();
box_type();
procmon();
logmon();
netbackup();
webtop();
impact();
rad();
#--------------------------------------#
trap_dest();
osmf_tools();
disk_space();
omnibus();
disk_size();




$script->print('exit');
}
}
}
 
M

mark1.thompson45

this is the jumpstart subroutine that I left off the previous post:-

sub jump_start
{
#print "\n\nIN JUMP START\n";
$jump = 1;
Telnet_To_Device();
$jump_host = $Data[1];
$uid = $Data[2];
$pwd = $Data[3];
$jump = 0;
Telnet_To_Device();
}
 
R

robic0

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
telnet from that host to a 2nd machine, I cannot get this to work, I
merely start anothet telnet session (spawn a new telnet session) from
my host machine.

i.e.

this works:-
host machine -------> machine A

this does not:-
host machine -------> machine A -----------> machine B


I am using:-

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

I need to do this as some devices (machine B) I
am trying to contact can only be accessed from a jumpstart server
(machine A).


cheers, Mark.

Thats a good question. The only reason I can see to try
something like this is if seperate networks.

The connectiion is actually:

host machine (you, client) --------------> machine A (server)

machine A (your telnet session)----------> machine A (start a telnet client)

machine A (your remote client)-----------> machine B (server)

between remote machine A (start a telnet client)---------> machine B (server)
you have to have machine B's i/o console redirected to you the host machine.

This isin't something you want to try with the perl net::telnet module until
you know it works manually. The big problem with telnet is the Unix/Windows
conflicting clients as it relates to the Telnet standard protocol.
So trying this between OS's is just asking for trouble.

I have automated a telnet session from a client windows to a unix machine with
net::telnet. There are limitations. I have made workarounds for them.
I wrote a module (class) for this that wraps net::telnet. If you can get it working
by hand, let me know and I'll post the module here and you can give it a try.

-robic0-
 
R

robic0

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
telnet from that host to a 2nd machine, I cannot get this to work, I
merely start anothet telnet session (spawn a new telnet session) from
my host machine.

i.e.

this works:-
host machine -------> machine A

this does not:-
host machine -------> machine A -----------> machine B


I am using:-

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

I need to do this as some devices (machine B) I
am trying to contact can only be accessed from a jumpstart server
(machine A).


cheers, Mark.

Thats a good question. The only reason I can see to try
something like this is if seperate networks.

The connectiion is actually:

host machine (you, client) --------------> machine A (server)

machine A (your telnet session)----------> machine A (start a telnet client)

machine A (your remote client)-----------> machine B (server)

between remote machine A (start a telnet client)---------> machine B (server)
you have to have machine B's i/o console redirected to you the host machine.

This isin't something you want to try with the perl net::telnet module until
you know it works manually. The big problem with telnet is the Unix/Windows
conflicting clients as it relates to the Telnet standard protocol.
So trying this between OS's is just asking for trouble.

I have automated a telnet session from a client windows to a unix machine with
net::telnet. There are limitations. I have made workarounds for them.
I wrote a module (class) for this that wraps net::telnet. If you can get it working
by hand, let me know and I'll post the module here and you can give it a try.

-robic0-

Just one other thing. If you intend to automate with net::telnet from A to B
you will need net::telnet on machine A (as a client) as well.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top