Dynamic IP script for Internode

WWW::Mechanize script for programmatically obtaining the current (dynamic) IPv4 and IPv6 addresses assigned to an Internode ADSL session:

#!/usr/bin/perl

use strict;
use warnings;
use WWW::Mechanize;

## Get current session data for our Internode session

my $mech = WWW::Mechanize->new();
my $user = ""; ## Enter Internode username
my $pass = ""; ## Enter Internode password

$mech->get('https://secure.internode.on.net/myinternode/sys0/login');
$mech->form_number(2);
$mech->set_fields(username => $user, password => $pass);
$mech->click('action');
$mech->follow_link (url_regex => qr/currentsessions/);

my $output = $mech->text();

## Locate IPv4 address in output
## ('IPv4:' on one side, '(dynamic)' on the other side)

my $v4_left = index ($output, "IPv4:") + 5;
my $v4_right = index ($output, "\(dynamic\)");

## Move IPv4 address in to its' own variable
## Remove new lines, leading and trailing spaces

my $ipv4 = substr $output, $v4_left, ($v4_right - $v4_left);
chomp $ipv4;
$ipv4 =~ s/^\s+//;
$ipv4 =~ s/\s+$//;

## Now do the same for the dynamically-assigned IPv6 address
## ('IPv6:' on one side, '(dynamic)' on the other side)

my $v6_left = index ($output, "IPv6:") + 5;
my $v6_right = rindex ($output, "\(dynamic\)");

## Move IPv6 address in to its' own variable
## Remove new lines, leading and trailing spaces

my $ipv6 = substr $output, $v6_left, ($v6_right - $v6_left);
chomp $ipv6;
$ipv6 =~ s/^\s+//;
$ipv6 =~ s/\s+$//;

## Print output

print "$ipv4\n";
print "$ipv6\n";

exit;