jpavel has asked for the wisdom of the Perl Monks concerning the following question:
I authorize fine to the first node, but I never see my port forward open up on my local machine. The second connect fails on unable to connect to <host>:<port>. Here's the debug output:my $tunnel1 = Net::SSH2->new(); $tunnel1->debug(1); $tunnel1->connect($host) or die "connect to DMZ failed"; $tunnel1->auth_password($user, $rzPass) or die "DMZ auth failed"; $tunnel1chan = $tunnel1->channel(); $tunnel1chan->shell(); $tunnel1->tcpip($host2, 22, '127.0.0.1', $rzPort); my $tunnel2 = Net::SSH2->new(); $tunnel2->connect('127.0.0.1', $rzPort) or die "connect to PLEX fa +iled"; $tunnel2->auth_password($user, $yzPass) or die "PLEX auth failed";
And note, I call the shell and channel because I saw DESTROYS coming in before the tcpip call... I figured I didn't want that to happen, and this at least preserves the objects until after I make that call. FWIW, I can establish the tunnels through system calls to plink, but I'd really like to minimize any use of external binaries... plus without direct manipulation of the plink session, I'm utilizing timers to "guess" when the connection and authorization occurs. I must say, the syntax doesn't seem to make much sense to me... what I *expect* the M.O. to be is similar to the plink commands:libssh2_channel_open_ex(ss->session, pv_channel_type, len_channel_type +, window_size, packet_size, ((void *)0) , 0 ) -> 0x1ea5664 libssh2_channel_direct_tcpip_ex(ss->session, (char*)host, port, (char* +)shost, sport) -> 0x1ea5544 Net::SSH2: created new object 0x1f362fc Net::SSH2::DESTROY object 0x1f362fc Net::SSH2::Channel=GLOB(0x1d25ff4)Net::SSH2::Channel::DESTROY Net::SSH2::Channel::DESTROY Net::SSH2::DESTROY object 0x1caf124
...thus establishing the forwarding before you connect, similar to the way you call ssh with "-L <local port>:<remote server>:<remote port>". Any thoughts, help, experience, or documentation on Net::SSH2's tcpip call?my $tunnel1 = Net::SSH2->new(); $tunnel1->debug(1); $tunnel1->tcpip($host2, 22, '127.0.0.1', $rzPort); $tunnel1->connect($host) or die "connect to DMZ failed"; $tunnel1->auth_password($user, $rzPass) or die "DMZ auth failed"; $tunnel1chan = $tunnel1->channel(); $tunnel1chan->shell(); my $tunnel2 = Net::SSH2->new(); $tunnel2->connect('127.0.0.1', $rzPort) or die "connect to PLEX failed +"; $tunnel2->auth_password($user, $yzPass) or die "PLEX auth failed";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Net::SSH2 and tcpip forwarding
by zentara (Cardinal) on May 26, 2009 at 13:23 UTC |