Skip to content

Instantly share code, notes, and snippets.

@dex4er
Created January 19, 2012 15:09
Show Gist options
  • Save dex4er/1640514 to your computer and use it in GitHub Desktop.
Save dex4er/1640514 to your computer and use it in GitHub Desktop.
VPN via interactive session
#!/usr/bin/perl
# expect.pl (c) 2012 Piotr Roszatycki <dexter@debian.org>
use strict;
use Expect;
die "Usage: $0 cmd [-echo] expect1 send1 expect2 send2 ...\n"
unless @ARGV;
my $cmd = shift @ARGV;
my $exp = Expect->spawn($cmd)
or die "Cannot spawn $cmd: $!\n";
if ($ARGV[0] eq '-echo') {
shift @ARGV;
$exp->slave->stty(qw(-echo));
$exp->log_stdout(0);
}
while (@ARGV) {
my $expect = shift @ARGV;
$exp->expect(10, $expect) or die "Cannot expect $expect\n";
my $send = shift @ARGV;
$exp->send(My::interpolate($send));
$exp->exp_continue;
}
$exp->interact();
sub My::interpolate {
local $_ = shift;
return eval "qq($_)";
}
#!/bin/sh
IPNET=10.0.2.0
IPHOST="${IPNET%.0}.2"
SELF=`cd $(dirname $0); pwd`/`basename $0`
if [ -z "$I_AM_IN_PPPD" ]; then
export I_AM_IN_PPPD=true
exec /usr/sbin/pppd pty "$SELF" nodetach local :$IPHOST
fi
expect.pl \
"ssh -t -e none some.server.example.com" \
\
"Enter PIN for 'eToken':" \
"1234\n" \
\
"user@some's password: " \
"mypassword\n" \
\
"$ " \
"slirp 'special addr $IPNET' ppp\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment