Friday, March 19, 2010

Python script for sending free SMS to any mobile using

NOTE: This script is not working now. Till that is fixed, refer to this link for a perfectly working sms sending script.

You can use this site to automate sms sending on occurrence of a desired event..
This script is similar to my earliest script, but this time it uses a different site

Its better than the previous scrpt because:-
  • Command line parameters support is now available (ex. ./ -h)
  • way2sms is faster than mycantos
  • The sms sent has the sender number as your number & not something like "TA-Mycantos"

This time I also had to include the feature of urlencode to encode my message bcos this was the way the did on its end while doing POST form..

Also, if the script doesnt work for you, install the addon "View HTTP Headers" in firefox and login to way2sms and goto send sms page.. Enter the mobile number to send and message text. Before pressing send, goto tools-> View HTTP Headers, to show the sidebar & check that the number in the script matches to that shown by http header.  For me it was 750000, for my friend it was 950000. So, this varies sometimes and this is done by the way2sms to avoid making of scripts like these.. In the script, this value is set to 950000..

  • If you want to have an idea as to how can script like this be made, take a look at my previous post.
I have checked this script on LINUX with python 2.6 and it works fine.. If you have any problem, feel free to leave comments...


__author__ = """
NAME: Abhijeet Rastogi (shadyabhi)

import cookielib
import urllib2
from getpass import getpass
import sys
from urllib import urlencode
from getopt import getopt

ask_username = True
ask_password = True
ask_message = True
ask_number = True

def Usage():
    print '\t-h, --help:  View help'
    print '\t-u, --username: Username'
    print '\t-p, --password: Password'
    print '\t-n, --number: numbber to send the sms'
    print '\t-m, --message: Message to send'

opts, args = getopt(sys.argv[1:], 'u:p:m:n:h',["username=","password=","message=","number=","help"])

for o,v in opts:
    if o in ("-h", "--help"):
    elif o in ("-u", "--username"):
        username = v
        ask_username = False
    elif o in ("-p", "--password"):
        passwd = v
        ask_password = False
    elif o in ("-m", "--message"):
        message = v
        ask_message = False
    elif o in ("-n", "--number"):
        number = v
        ask_number = False

#Credentials taken here
if ask_username: username = raw_input("Enter USERNAME: ")
if ask_password: passwd = getpass()
if ask_message: message = raw_input("Enter Message: ")
if ask_number: number = raw_input("Enter Mobile number: ")

#Logging into the SMS Site
url = ''
data = 'username='+username+'&password='+passwd+'&Submit=Sign+in'

#Remember, Cookies are to be handled
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))

# To fool way2sms as if a Web browser is visiting the site
opener.addheaders = [('User-Agent','Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20091020 Ubuntu/9.10 (karmic) Firefox/3.5.3 GTB7.0')]
    usock =, data)
except IOError:
    print "Check your internet connection"

#urlencode performed.. Because it was done by the site as i checked through HTTP headers

message = urlencode({'message':message})
message = message[message.find("=")+1:]

#SMS sending
send_sms_url = ''
#Check this line with HTTP Headers, if script is not working
send_sms_data = 'custid=undefined&HiddenAction=instantsms&Action=custfrom950000&login=&pass=&MobNo='+number+'&textArea='+message
opener.addheaders = [('Referer','')]

    sms_sent_page =,send_sms_data)
    inp = open("log.html","w")

except IOError:
    print "Check your internet connection( while sending sms)"
print "SMS sent!!!"


  1. Hi its really very nice i enjoyed a lot to visit..Handset prices

  2. Such a very good and informative post. thanks for the information...

  3. Hi,
    1)im assuming the encoding is UTF-8?
    2)i get this error:

    File "", line 21
        print '\t-h, --help:  View help'
    with a copy-paste of your code.

    please assist. thanks.

  4. python3.0 broke backward compatibility and thats pretty sad. :(

  5. @Nikhil
    You are getting this error because you are using python3.0 or greater. You are getting this error because in python 3.0 and greater, they have changed the syntax of "print". Use python 2.6, the script will just run fine..

    For more info on whats new in python 3.0 goto:-

  6. Hi its really very nice i enjoyed a lot to visit..latest mobile phones

  7. Ah, thanks. Response much appreciated

  8. hi frnds its not understandable by me can u xplain step by step and is it works in XP

  9. yes, this script works on windows too. You just need to install the python interpreter (
    Make sure that you dont downlaod the 3.1 version. Its the latest version but my script will not run on that version...

    After you have downloaded the file, install it like you install any other software.

    Copy my script into a file and save it as extenstion .py...
    Double click the script, and it will ask you for the details...
    This script also supports command line parameters which is very useful since you dont actually need to enter all details everytime, but thats not the stuff which is very much understandable to windows users..

    Pls be specific on what kind of doubt you have, and i will be happy to help.. :)

  10. it just says SMS sent!!!, however, sms is not sent, after reading your blog, i was able to fix it. Thx buddy

  11. This comment has been removed by a blog administrator.

  12. Hi, I am nOOb at this.. can you please explain to me where i save the script and how i open it? an dhow i can send a sms

  13. If you asked this question, I am pretty sure you are on windows..
    So, for windows...

    Click on "View Plain" (link is present where the code starts).. A new window will open and it will contain the code. Copy paste that code in a file and save it as .py file.

    You need to have python installed ( ).
    Install the 2.6 version..
    Then double-click the .py file.......


    just do $./

    if you saved the file as and it is in the current directory.

  14. can any one help me i need online reminder with sms alert script . please someone helped me.

  15. Why dont you remove these spammers.

  16. I tried it in windows with python2.6 and getting message sent mesg. but not getting on mobile.pls let me know if any modification required for windows.

  17. I have tried this script in ubuntu 10.04.It displays the message SMS sent and even the log.html file has the image but then no sms is received.Please do help me find out what is going wrong here.

  18. I am the same person who as posted above.I even tried changing the value using HTTP viewer but I do not get any such number:

    My outputs of the HTTP viewer are:

    GET //jsp/InstantSMS.jsp?val=0 HTTP/1.1

    and then instead of custid I have a long Cookie
    What should I do now?

  19. Hi Abhijeet,

    I am trying this script in rhel5.4 and python version is 2.4.3.I don't face any problem in importing the modules used by the script.Though the script says "SMS sent" message,i am not receiving message in my mobile. Even I made the changes mentioned by you above.I tried installing python 2.6 in my windows machine and tried executing this script but cookielib import fails.Is there anything specific to install other than python?. I used "Live HTTP header" and made the changes appropriately in the script to my knowledge and also i see 'Referer','' is different in 'Live HTTP header' even i tried changing this but didn't help and log.html is also empty.

  20. This seems to be great site for sms software with the help of this we can send SMS directly from PC without the use of mobile phones.i would surely like to try their service.i had been relying on

  21. hi,

    thanks for the work and for sharing it with everyone. i tried this on linux and it worked well initially (except that i had to fix the "Action=" param by looking at the page sources). i had problems again today and it turned out to due to the same thing. it seems that this param keeps changing, so it might be more straightforward to simply
    - first login
    - fetch the sms form ${url}/jsp/InstantSMS.jsp
    - fill the form
    - submit the form
    any comments? or any other way to fix this? i am somewhat new to python, that's my excuse for not doing it myself.

    next steps are to buy a static IP address, set up a simple server on it, and write a midlet to submit the sms to this server over GPRS (costs 30ps/20k on airtel).

    thanks again

  22. i am getting check internet connection even though i have working internet connection........... can anyone help me out

  23. working code

  24. To give your jokes your personal touch, you can record the jokes in your voice and forward them as voice SMS.

  25. Working code

  26. It is interesting, I'm checking it.

  27. pl let me know how can i use this script on my website, i ve a blogger and i want to use this on my blogger, pl must guide me.

  28. You would have to make a javascript widget for yourself & then add it in settings'.

  29. thanks for the information hopefully can provide value to the many benefits

  30. hello guys, especially interested to know if this codes involves using a gsm modem or any hardware to use the free sending of sms?please reply

  31. @lizzie

    it doesn't require a gsm modem. It uses free websites to send the SMS. You can do the same by logging into the site and then sending SMS from there but I wrote a python script that simulates that just for ease.

  32. nice work dude.

    i was forced to take a jab at this and now i have a slightly improved version of someone else's script here:

    it supports a phonebook (you can use names instead of numbers, on the command line). you'll need a little utility script to add numbers to the phone book:

    it also supports sending a message from a file (using a "-f" option).

    the parameter order may be reversed for convenience if anyone wants.

    this whole thingy works for me right now on linux.


  33. i am connected to internet nut it shows
    "check your internet connection"

  34. i am connected to internet nut it shows
    "check your internet connection"   how to solve that problem

  35. it shows "check your internet connection". I am connected to internet. Wats the problem?????

  36. Two issues, when the code prompts for a Username (which actually should be user-phone-number), an incorrect password for a given username should echo something like "Incorrect password, Try again", but it is just continuing. And secondly, even though I am not using any proxy or something, I am getting the message "Check your internet connection". Help?

  37. i use proxy and i get error "Check your internet connection", can u pls help me.

  38. Hi Abhijeet Rastog,

    me too getting same error..

    "check your internet connection"

    but i m not behind proxy.

    i am using data card usb internet

  39. iam behind a proxy, getting "check your internet connection" error. how to solve this