Telenor SMS

From ivc wiki
(Redirected from Telenor SMS Script)
Jump to navigationJump to search

As a Telenor mobile subscriber, you have the possiblity to send SMS messages via their website. Also, for as long as I can remember, the first 30 messages each month are free.

This is a simple script I made to simplify the process. Instead of having to log-in to post a message, why not do it from the command-line.

Telenor Norway

Website

I've used the script below to create a new website, called telenorsms.no. You only need to provide the Telenor subscription details and fill in the recipient's phone number and end message. You can choose to click 'Remember' to automatically fill inn the log-in credentials on subsequent visits to the site.

Shell script

The shell script utilizes wget for the web-requests and has some sanitation, error, and debugging functionality. Please feel free to alter the script and give me suggestions for improvements.

#!/bin/sh
#
# Telenor Send SMS Script - by ivc
#
# 2009-02-03: Initial version
#

# Settings
username=<your telenor cellnumber>
password=<account password>
debug=false


# Rest of the script, no editing needed
tonumber=$1
message=`echo $@|sed -e 's/'"$tonumber"' //g' -e 's/ /%20/g'`
cwd=`dirname $0`
cookiesfile=$cwd/telenor_cookies.txt

echo -e "\n Telenor Send SMS Shell Script - by ivc\n"

# Some sanitation
if [ -z `which wget` ]; then echo -e "  wget binary is missing or is not in the path, install wget and get back to the script.\n"; exit; fi;
if [ -z $1 ] || [ -z $2 ]; then echo -e "  Missing arguments!\n\n  Usage: $0 <number> <text message>\n  E.g. $0 99933322 Hi m8, bouldering today?\n"; exit; fi

# Debug mesages and setup
if [ $debug == true ]; then echo "  Sending message \"$message\" to number $tonumber"; fi


# Login
echo -e "  Logging in..."
login=`wget --quiet -O- --save-cookies=$cookiesfile --keep-session-cookies \
 --post-data="j_username=$username&j_password=$password&fromweb=undefined" https://telenormobil.no/minesider/login.do`

if [ $debug == true ]; then echo "$login"; fi

loginsuccessful=`echo $login|grep "$username"`
toomanyattempt=`echo $login|grep "sperret"`

if [ -n "$loginsuccessful" ]; then echo -e "  Successfully logged in.";
elif [ -n "$toomanyattempt" ]; then echo -e "  Server reports too many failed attempts, try again in 30 minutes.\n"; exit;
else echo -e "  Failed to log in, check the username and password!\n"; exit; fi


# Send SMS
echo -e "  Sending message..."
sendsms=`wget --quiet -O- --load-cookies=$cookiesfile --keep-session-cookies \
 --post-data="toAddress=$tonumber&message=$message&b_send=Send" https://telenormobil.no/ums/compose/sms/process.do`

if [ $debug == true ]; then echo "$sendsms"; fi

sendsmssuccessful=`echo $sendsms|grep "Meldingen er sendt"`

if [ -n "$sendsmssuccessful" ]; then echo -e "  Message sent!"; else echo -e "  Failed to send message, try again later.\n"; exit; fi


# SMS left count
smsleft=`wget --quiet -O- --load-cookies=$cookiesfile --keep-session-cookies https://telenormobil.no/ums/compose/sms.do`

if [ $debug == true ]; then echo "$smsleft"; fi

smsleftcount=`echo $smsleft|awk -F"web: " '{print $2}'|sed 's/<br\/>/ /g'|cut -d" " -f1`

if [ -n "$smsleftcount" ]; then echo -e "\n  Number of free web SMS messages left: $smsleftcount\n"; fi


# Delete cookies file
rm -f "$cookiefile"

Save it as telenor_send_sms.sh and make it executable, chmod +x telenor_send_sms.sh.

Update 2010-08-02:

Here is a small and simple shell script to login and send a text using ./sendsms-simple.sh <reception> <message>.

#!/bin/sh
/usr/bin/wget -O /dev/null -q "http://telenormobil.no/ums/login/check.do?phonenumber=PUTYOURNUMBER&password=PUTYOURPASS" \
"http://telenormobil.no/ums/compose/sms/process.do?toAddress=$1&message=$2&b_send=OK"
exit

mIRC script

mIRC is an IRC client and is used to chat to people all around the world, in different channels.

This script is something I wrote and put together in 2005. The original script still works in 2009, showing the conservatism and reliance that is Telenor.

Usage:

  • Load script, one time event, in status window: /load -rs telenorsms_v2.mrc
  • Set your Telenor subscription phone number/login id: /telenorsms <number>
  • Set the login password: /telenorsms <pass>
  • Send message: /telenorsms <recipient> <message>
; TelenorSMS v2 - ivc 2006
; ivc@x-pec.com
; Ref: http://m4rc.ath.cx/tutor/mSocket

; CONFIGURE
alias telenorsms { 
  sockclose telenor_send
  set %telenor_num $1
  set %telenor_msg $2-
  if ($1 == phone) && ($2 != $null) { set %telenor_phone $2 | echo -a TelenorSMS - Phone number $2 saved. | halt }
  if ($1 == pass) && ($2 != $null) { set %telenor_pass $2 | echo -a TelenorSMS - Password saved. | halt }
  if ($1 == remove) && ($2 != $null) { unset %telenor_phone | unset %telenor_pass | echo -a TelenorSMS - Settings cleared. | halt }
  if (%telenor_phone == $null) { echo -a TelenorSMS - Please configure your telenor phone number setting - /telenorsms phone <telenor mobil number> | halt }
  if (%telenor_pass == $null) { echo -a TelenorSMS - Please configure your telenormobil.no password setting - /telenorsms pass <telenormobil.no pass> | halt }
  echo -a TelenorSMS - Logging in...
  sockopen telenor_login telenormobil.no 80 
}

; LOGIN
on *:sockopen:telenor_login:{
  sockwrite -n $sockname GET http://telenormobil.no/ums/login/check.do?phonenumber= $+ %telenor_phone $+ &password= $+ %telenor_pass HTTP/1.1
  sockwrite -n $sockname Host: telenormobil.no
  sockwrite -n $sockname $crlf
}

on *:SOCKREAD:telenor_login: {
  if ($sockerr > 0) { return }
  var %tmp | sockread %tmp
  while ($sockbr) {
    if ( Set-Cookie: u* path=/ iswm %tmp ) {
     ; Set-Cookie: umswebsession=D1q2wh1DM2Sy2hjCZ8R3lgjDSwWGCtQL1gxy7vqJQ0LnTHNTC3wT!-997926277; path=/ 

      set %telenor_cookie1 $telenor_getvariables(%tmp)
    }
    if ( Set-Cookie: T* path=/ iswm %tmp ) {
      ; Set-Cookie: TelenorSession=ASPSESSION=285799310&COMMONSESSION=9000000013566319; path=/

     set %telenor_cookie2 $telenor_getvariables(%tmp)
    }
    sockread %tmp
  }
  echo -a TelenorSMS - Getting session token...
  timer 1 1 sockopen telenor_token telenormobil.no 80
  return
}

alias telenor_getvariables { var %tmp 
  %i = $regsub($1-,Set-Cookie: ,$chr(32),%tmp)
  %i = $regsub(%tmp,; path=/,$chr(32),%tmp)
  return %tmp 
}

; READ TOKEN
on *:sockopen:telenor_token:{
  sockwrite -n $sockname GET http://telenormobil.no/ums/compose/sms.do HTTP/1.1
  sockwrite -n $sockname Cookie: %telenor_cookie1 $+ ; %telenor_cookie2
  sockwrite -n $sockname Host: telenormobil.no
  sockwrite -n $sockname $crlf
}

on *:SOCKREAD:telenor_token: {
  sockclose telenor_login
  if ($sockerr > 0) { return }
  var %tmp | sockread %tmp
  while ($sockbr) {
    ;echo -a tokenpage: %tmp

if (( "> isin %tmp ) && ( ue=" isin %tmp )) {

      set %telenor_token $telenor_getvariables2(%tmp)
      ;echo -a found token: �4 $+ %tmp $+ �
    }
    if ( SMS fra web: isin %tmp ) {
      set %telenor_smsleft $telenor_getvariables3(%tmp)
      ;echo -a sms left found: �4 $+ %tmp $+ �
    } 
    sockread %tmp
  }
  timer 1 1 sockopen telenor_send telenormobil.no 80
  return
}

; GET TOKEN
alias telenor_getvariables2 { var %tmp 
  %i = $regsub($1-,.*ue=\" ,$chr(32),%tmp)

%i = $regsub(%tmp,\">,$chr(32),%tmp)

  return %tmp 
}

; SMS LEFT COUNT
alias telenor_getvariables3 { var %tmp 
  %i = $regsub($1-,.*SMS fra web: ,$chr(32),%tmp)

%i = $regsub(%tmp,,$chr(32),%tmp) return %tmp }  ; SEND SMS on *:sockopen:telenor_send:{ sockwrite -n $sockname GET http://telenormobil.no/ums/compose/sms/process.do? $+ %telenor_cookie1 $+ & $+ %telenor_cookie2 $+ &toAddress= $+ %telenor_num $+ &message= $+ %telenor_msg $+ &multipleMessages=true&b_send=&org.apache.struts.taglib.html.TOKEN= $+ %telenor_token HTTP/1.1 sockwrite -n $sockname Cookie: %telenor_cookie1 $+ ; %telenor_cookie2 sockwrite -n $sockname Host: telenormobil.no sockwrite -n $sockname $crlf } on *:SOCKREAD:telenor_send: { sockclose telenor_token if ($sockerr > 0) { return } var %tmp | sockread %tmp while ($sockbr) { ;echo -a successpage: %tmp if ( *feil* iswm %tmp ) { echo -a TelenorSMS - Error } if ( *logg inn* iswm %tmp ) { echo -a TelenorSMS - Not logged in } if ( *logg ut* iswm %tmp ) { echo -a TelenorSMS - Sending message... } if ( *angi adresse* iswm %tmp ) { echo -a TelenorSMS - Missing number - Usage: /telenorsms <receiver's number> <message> } if ( *angi innhold* iswm %tmp ) { echo -a TelenorSMS - Missing content - Usage: /telenorsms <receiver's number> <message> } if ( *Meldingen ble ikke sendt* iswm %tmp ) { echo -a TelenorSMS - Failed to send message! } if ( *Meldingen er sendt* iswm %tmp ) { echo -a TelenorSMS - Message successfully sent! Free SMS left: %telenor_smsleft } sockread %tmp } unset %telenor_msg unset %telenor_num unset %telenor_cookie1 unset %telenor_cookie2 unset %telenor_sent unset %telenor_sent2 unset %telenor_token return }

Telenor Sweden

Anton Johansson sent me a modified version for Telenor Sweden. Just minor adjustments had to be made.

#!/bin/sh
#
# Telenor Send SMS Script - by ivc
#
# 2009-02-03: Initial version
#

# Settings
username=
password=
debug=false


# Rest of the script, no editing needed
tonumber=$1
message=`echo $@|sed -e 's/'"$tonumber"' //g' -e 's/ /%20/g'`
cwd=`dirname $0`
cookiesfile="telenor_cookies.txt"

echo -e "\n Telenor Send SMS Shell Script - by ivc\n"

# Some sanitation
if [ -z `which wget` ]; then echo -e "  wget binary is missing or is not in the path, install wget and get back to the script.\n"; exit; fi;
if [ -z $1 ] || [ -z $2 ]; then echo -e "  Missing arguments!\n\n  Usage: $0 <number> <text message>\n  E.g. $0 99933322 Hi m8, bouldering today?\n"; exit; fi

# Debug mesages and setup
if [ $debug == true ]; then echo "  Sending message \"$message\" to number $tonumber"; fi


# Login 
echo -e "  Logging in..."
login=`wget --quiet --no-check-certificate -O- --save-cookies=$cookiesfile --keep-session-cookies \
--post-data="msisdn=$username&password=$password" https://minasidor.telenor.se/app/minasidor/jsp/web/action.jsp?sId=VFLIVE`

if [ $debug == true ]; then echo "$login"; fi

loginsuccessful=`echo $login|grep "Logga ut"`
toomanyattempt=`echo $login|grep "nger och har blivit utel"`

if [ -n "$loginsuccessful" ]; then echo -e "  Successfully logged in.";
elif [ -n "$toomanyattempt" ]; then echo -e "  Server reports too many failed attempts, you need to change your password manually.\n"; exit;
else echo -e "  Failed to log in, check the username and password!\n"; exit; fi


# Send SMS -O- --quiet 
echo -e "  Sending message..."
sendsms=`wget -O- --quiet --load-cookies=$cookiesfile --keep-session-cookies --no-check-certificate \
--post-data="currentBtn=mainSendButton&comingFromMain=true&singleName=$tonumber&smsText=$message&endPhrase=" https://minasidor.telenor.se/app/minasidor/sms/send.do`

if [ $debug == true ]; then echo "$sendsms"; fi

sendsmssuccessful=`echo $sendsms|grep "Dina SMS har skickats till"`

if [ -n "$sendsmssuccessful" ]; then echo -e "  Message sent!"; else echo -e "  Failed to send message, try again later.\n"; fi


# SMS left count
smsleft=`wget --quiet -O- --load-cookies=$cookiesfile --no-check-certificate --keep-session-cookies https://minasidor.telenor.se/app/minasidor/sms/main.do`
if [ $debug == true ]; then echo "$smsleft"; fi

smsleftcount=`echo $smsleft|awk -F"skickat <b>" '{print $2}'|sed 's/<\/b>/ /g'|cut -d" " -f1`

if [ -n "$smsleftcount" ]; then echo -e "\n  You have sent: $smsleftcount messages this month.\n"; fi


# Delete cookies file
rm -f "$cookiesfile"

Save it as telenor_send_sms.sh and make it executable, chmod +x telenor_send_sms.sh.


Telenor SMS Sweden 2016

Thanks to Bøf for the following update. Much appreciated.

#!/bin/bash
#
# Telenor Send SMS Script
#
# 2009-02-03: Initial version by ivc - http://beta.ivc.no/wiki/index.php/Telenor_SMS
# 2016-07-15: Updated by bof to work with telenor.se
#

# Settings
username=qwerty
password=123456
debug=false


# Rest of the script, no editing needed
tonumber=$1
message=`echo $@|sed -e 's/'"$tonumber"' //g' -e 's/ /%20/g'`
cwd=`dirname $0`
cookiesfile=$cwd/telenor_cookies.txt

echo -e "\n Telenor Send SMS Script\n"

# Some sanitation
if [ -z `which wget` ]; then echo -e "  wget binary is missing or is not in the path, install wget and get back to the script.\n"; exit; fi;
if [ -z $1 ] || [ -z $2 ]; then echo -e "  Missing arguments!\n\n  Usage: $0 <number> <text message>\n  E.g. $0 99933322 Hi m8, bouldering today?\n"; exit; fi

# Debug mesages and setup
if [ $debug == true ]; then echo "  Sending message \"$message\" to number $tonumber"; fi


# Login
echo -e "  Logging in..."

login=`wget --quiet -O- --save-cookies=$cookiesfile --keep-session-cookies --post-data="username=$username&password=$password& fromweb=undefined" https://minasidor.telenor.se/minasidor/login`

if [ $debug == true ]; then echo "$login"; fi

loginsuccessful=`echo $login|grep "$username"`
toomanyattempt=`echo $login|grep "och ditt konto har blivit"`

if [ -n "$loginsuccessful" ]; then echo -e "  Successfully logged in.";
elif [ -n "$toomanyattempt" ]; then echo -e "  Too many failed attempts, the account is locked.\n"; exit;
else echo -e "  Failed to log in, check the username and password!\n"; exit; fi


# Add Number
echo -e "  Adding number..."

addnumber=`wget --quiet -O- --load-cookies=$cookiesfile --keep-session-cookies https://minasidor.telenor.se/minasidor/sms/AddSmsReceiverAjaxAction.do?type=SINGLENAME\&value=$tonumber`

if [ $debug == true ]; then echo "$addnumber"; fi

addnumbersuccessful=`echo $addnumber|grep $tonumber`

if [ -n "$addnumbersuccessful" ]; then echo -e "  Added number to list."; else echo -e "  Failed to add number, try again later.\n"; exit; fi


# Send SMS
echo -e "  Sending message..."

sendsms=`wget --quiet -O- --load-cookies=$cookiesfile --keep-session-cookies --post-data="singleName=&smsText=$message&endPhrase=" https://minasidor.telenor.se/minasidor/sms/send.do`

if [ $debug == true ]; then echo "$sendsms"; fi

sendsmssuccessful=`echo $sendsms|grep "Dina sms har skickats"`

if [ -n "$sendsmssuccessful" ]; then echo -e "  Message sent!"; else echo -e "  Failed to send message, try again later.\n"; exit; fi


# SMS left count
smsleft=`wget --quiet -O- --load-cookies=$cookiesfile --keep-session-cookies https://minasidor.telenor.se/minasidor/sms/main.do`

if [ $debug == true ]; then echo "$smsleft"; fi

smsleftcount=`echo $smsleft|awk -F"Du har \<strong\>" '{print $2}'|sed 's/<\/strong> fria Web/ /g'|cut -d" " -f1`

if [ -n "$smsleftcount" ]; then echo -e "\n  Number of free web SMS messages left: $smsleftcount\n"; fi


# Delete cookies file
rm -f "$cookiefile"

References