Version 2 of small perl mechanize script to send sms from danish telco provider Bibob

A year ago I wrote a small perl Mechanize script to send sms from the command line (very useful for scripts) utilizing the web-sms service you get as a Bibob customer.

Now a year later I actually found some use for it, but it didn’t work anymore due to the fact that Bibob had changed their website since then. And not just the graphics and layout, but the whole shebang.

I have made some very small changes to the perl script to make it work again and I appriciate the versatility of perl and that the Bibob webmasters obviously thought a great deal about the upgrade.

The new code can be downloaded here, hbut is also included verbatim in this post

#!/usr/bin/perl -w

##############################################################################
#
# File:         bibob_sms.pl
# Type:         bot
# Description:  Send an SMS using bibob websms and perl mechanize
# Language:     Perl
# Version:      2.0
# License:      BeerWare – Thomas S. Iversen wrote this file. As long as you
#               retain this notice you can do whatever you want with this
#               stuff. If we meet some day, and you think this stuff is worth
#               it, you can buy me a beer in return. Thomas
# History:
#               2.0 – 2011.07.26 – New version due to total bibob.dk relayout
#               1.0 – 2011.07.28 – Intial version
#
# (C) 2011,2012 Thomas S. Iversen (zensonic@zensonic.dk)
#
##############################################################################

use strict;
use WWW::Mechanize;
use File::Basename;

# Variables controlling bot behaviour

my $sms_url=‘https://www.bibob.dk/min-konto/web-sms’;
my $login_url=‘https://www.bibob.dk/’;

my $script=basename($0);
die "$script <bibob mobile number> <bibob password> <recipeient number> <message>" if(!($#ARGV+1 == 4));

my $username=$ARGV[0];
my $password=$ARGV[1];
my $recipients=$ARGV[2];
my $message=$ARGV[3];

#
# You should not need to alter anything below this line
#

#
# Main code.
#

# Create mechanize instance
my $mech = WWW::Mechanize->new( autocheck => 1 ); #Create new browser object
$mech->agent_alias( ‘Windows IE 6′ ); #Create fake headers just in case
$mech->add_header( ‘Accept’ => ‘text/xml,application/xml,application/xhtml\+xml,text/html,text/plain,image/png’ );
$mech->add_header( ‘Accept-Language’ => ‘en-us,en’ );
$mech->add_header( ‘Accept-Charset’ => ‘ISO-8859-1,utf-8′ );
$mech->add_header( ‘Accept-Language’ => ‘en-us,en’ );
$mech->add_header( ‘Keep-Alive’ => ’300′ );
$mech->add_header( ‘Connection’ => ‘keep-alive’ );

# Get login page
$mech->get($login_url);
$mech->success or die "Can’t get the login page";

# Submit the login form with username (mobilnumber) and password
$mech->submit_form(with_fields => { ‘phoneNumber’ => $username, ‘password’ => $password });
$mech->success or die "Could not login";

# Get sms page
$mech->get($sms_url);
$mech->success or die "Could not get sms page";

# Send sms by submitting sms form
$mech->submit_form(with_fields => { ‘recipients’ => $recipients, ‘message’ => $message });
$mech->success or die "Could not send sms";

# Figure out status
my $html = $mech->content();
die "Form submitted, but message does not appear to be sent" if(!$html=~/Beskeden blev afsendt/ig);
exit 0;

Leave a Reply

You must be logged in to post a comment.