Zuletzt geändert: So, 09.01.2005

«11C» as8758.pl «PDF», «POD»



Download
#!/usr/bin/perl

use warnings;
use strict;

BEGIN { $ENV{PATH} = "/sbin:/usr/sbin:$ENV{PATH}" }
use WWW::Mechanize;
use File::Temp qw< tempfile >;

use constant {
  USERNAME => "iblech",
  PASSWORD => "...",
  EXT_IF   => "ippp0",
};

my $ipv4_public = (split /\s+/, `ip addr show dev @{[EXT_IF]} | grep inet`)[2];
$ipv4_public =~ s/\/.*//;

die "Couldn't get public IPv4 address!\n" unless $ipv4_public;
print STDERR "Public IPv4 address: $ipv4_public\n";

print STDERR "Logging in to as8758...\n";
my $mech = WWW::Mechanize->new;
$mech->get("http://tunnelbroker.as8758.net/login.php");
$mech->form_number(1);
$mech->field(username => USERNAME);
$mech->field(password => PASSWORD);
$mech->click("Login");

print STDERR "Changing tunnel parameters...\n";
$mech->form_number(1);
$mech->field(ipv4tunnelend => $ipv4_public);
$mech->click("ipv4change");

print STDERR "Downloading tunnel initialisation script...\n";
$mech->form_number(2);
$mech->field(OS => "linux24");
$mech->click("Generate");

print STDERR "Executing script...\n";
my ($fh, $fn) = tempfile();
print $fh $mech->content;
close $fh;
system qw< ifconfig tunnelbroker down >;
system "bash", $fn;
unlink $fn;