Page 1 of 1

Vodafone checker

Posted: Tue Feb 12, 2008 4:25 pm
by Snelvuur
Since i have a bundle of minutes together with my gf, she tends to call alot. To keep an eye that i'am not going over the limit i've made a small script which logs into vodafone website gets the amount of my bundle which is left. In this example it only shows it but you could put it on the website, or use it to send an sms out when you go below a certain amount (this is what i have) this is for dutch vodafone, maybe works on other, dont know.

Here's the code:

Code: Select all

#!/usr/bin/perl

use strict;
use warnings;
use LWP::UserAgent;
use Crypt::SSLeay;
use LWP::ConnCache;
use HTTP::Cookies;
use HTTP::Status;
use HTTP::Response;
use URI::URL;
#use LWP::Debug qw(+);

# 0=false, 1=true
my $DEBUG = 0;

# CA cert peer verification
$ENV{HTTPS_CA_FILE}  = "/root/scripts/cacert.cer";

my $password = "*******";
my $username = "*******";

if ($DEBUG){
    print "Username is: $username\n";
    print "Password is: ********\n";
}

# Create a user agent
my $ua = LWP::UserAgent->new();
push @{ $ua->requests_redirectable }, 'POST';
$ua->conn_cache(LWP::ConnCache->new());
$ua->cookie_jar(HTTP::Cookies->new());

# Get the login page
my $loginpage = "http://my.vodafone.nl/prive/my_vodafone?errormessage=&errorcode=";
my $response1 = $ua->get($loginpage);
if ($response1->is_error){
    print "Error - getting the login page\n";
    print $response1->status_line;
    exit;
}

# get ID parameter
$response1->content =~ /(<input value="+\S{32}" name="ID" type="hidden">)/;
my $ID = substr($1, 14, 32);

# Login My Vodafone
my $doLogin="https://login.vodafone.nl/signon?provider=myvodafone";
my $response2 = $ua->post($doLogin,
    ['username' => $username,
     'password' => $password,
     'loginerrorurl' => 'prive/my_vodafone',
     'assertionconsumerurl' => 'prive/my_vodafone',
     'inloggen' => 'inloggen',
     'ID' => $ID
    ],
    'content_type' => 'application/x-www-form-urlencoded'
);
if ($response2->is_error){
    print "Error - logging in\n";
    print $response2->status_line;
    exit;
}

$response2->content =~ /<div class="legend">&euro\;&nbsp\;(\d+,\d+)&nbsp\;van&nbsp/;
my $OVER = $1;

$response2->content =~ /\s&euro\;&nbsp\;(\d+,\d+)<\/div><\/div>/;
my $VAN = $1;

print "I still have $OVER euro over from the $VAN this month\n";
// Erik (binkey.nl)