Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   Help Required using NET::TELNET Module ?? (http://www.velocityreviews.com/forums/t895833-help-required-using-net-telnet-module.html)

mark1.thompson45@btinternet.com 12-29-2005 11:19 AM

Help Required using NET::TELNET Module ??
 
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.


Gratemyl 12-29-2005 12:14 PM

Re: Help Required using NET::TELNET Module ??
 

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
> 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


mark1.thompson45@btinternet.com 12-29-2005 12:31 PM

Re: Help Required using NET::TELNET Module ??
 
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');
}
}
}


mark1.thompson45@btinternet.com 12-29-2005 12:39 PM

Re: Help Required using NET::TELNET Module ??
 
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();
}


robic0 01-01-2006 12:18 AM

Re: Help Required using NET::TELNET Module ??
 
On 29 Dec 2005 03:19:39 -0800, 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
>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-



robic0 01-01-2006 12:24 AM

Re: Help Required using NET::TELNET Module ??
 
On Sat, 31 Dec 2005 16:18:39 -0800, robic0 wrote:

>On 29 Dec 2005 03:19:39 -0800, 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
>>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.


All times are GMT. The time now is 08:30 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57