It can be handy to send sms’es from scripts. In old time you could do that in Telia by sending a mail to <mobile number>@gsm1800.telia.dk. But that service was closed. Now that I am leaving Telia in favor of Bibob I saw that they had a websms service.
And so I combined their fine web service with my perl scripting skillz. The script can be downloaded here
Do not forget the agreement between you and bibob. You are only allowed to use the websms service (and thus this script) for personal use. I am not to blame if bibob closes your bibob account because you spam-smsed a lot of people.
The code is also included here:
#####################################################################
#
# File:Â Â Â Â Â Â Â Â bibob_sms.pl
# Type:Â Â Â Â Â Â Â Â bot
# Description:Â Send an SMS using bibob websms and perl mechanize
# Language:Â Â Â Â Perl
# Version:Â Â Â Â Â 1.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:
#Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 – 2011.07.28 – Intial version
#
# (C) 2011 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/bibob/bibob?cmd=websmssender’;
my $login_url=‘https://www.bibob.dk/bibob/bibob?cmd=loginFrame’;
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 => { ‘loginmsisdn’ => $username, ‘login-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.