Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

autarch (914)

autarch
  (email not shown publicly)
http://www.vegguide.org/

Journal of autarch (914)

Friday April 20, 2007
03:36 PM

More net pipes

[ #33052 ]

I figured out to make it work with a behind-NAT connection.

I have to connect to the server with ssh like this - ssh -A -R 9999:localhost:22 urth.org

Now I've updated my script to assume that there's a reverse tunnel on port 9999:

#!/usr/bin/perl
 
use strict;
use warnings;
 
use File::Temp qw(tempfile);
 
my ( $fh, $filename ) = tempfile();
 
print $fh $_ while <>;
 
seek $fh, 0, 0;
 
system( 'scp', '-P', 9999, '-o', 'StrictHostKeyChecking=no', $filename, 'localhost:' . $filename );
system( 'ssh', '-p', 9999, '-o', 'StrictHostKeyChecking=no', 'localhost', 'DISPLAY=:0.0 gnome-open ' . $filename );

I was getting lots of host key warnings, presumably because localhost is not really localhost here, it's my client machine.

This spits out some warnings, but it does the job just fine.

BTW, I love how scp uses "-P" for port and ssh uses "-p". Doh!

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • I think the warnings are because the keys on your machine are for localhost:22 whereas you are connecting to localhost:9999. You should be able to retain host key checks by telling ssh that it’s connecting through a proxy. Here I used netcat.

    Try this for extra evil (untested):

    #!/usr/bin/perl
    use strict;
    use warnings;

    open my $pipe, '|-', 'ssh', '-o', 'ProxyCommand=nc localhost 9999', 'localhost', 'perl';

    die "Can't fork: $!\n" unless defined $pipe;

    print $pipe <<'END_PERL';
    use strict;
    use warni