Send Free sms in India via Way2Sms login from Terminal using perl code

Dear Friends,

Greetings .!.

Happy to say you that I got perl code to send free sms using way2sms login. :-)

I used to search this for long time. But the key word is perl and way2sms. I dont know this keyword before.

If you search these two keywords at a time in internet, it will give you the proper code.
I got the perl code from this link http://digitalpbk.com/2009/12/perl-script-send-free-sms-any-mobile-number-india-using-way2sms

Yesterday I started to use this. Then I modified as per my usability. I hope this will satisfy all the users.

So here after from terminal itself, we can chat with our friends, if you feel pain to send sms from phone. :-)

Once you get the code, then you can make it as automated one to send spam msg to your friends :-) :-) :-)

If you are using ubuntu, then you need to install the following two packages.

sudo apt-get install libwww-mechanize-perl

sudo apt-get install libio-compress-zlib-perl

Then copy the below perl code into your system. Then save that file as ‘sms’.
Set the way2sms login username and password in that saved ‘sms’ code.

And move that file into $ sudo mv sms /usr/bin/sms

To make it as executable one do $ sudo chmod 755 /usr/bin/sms

Usage :
1. $ sms 9876543210 ‘hello’
2. $ sms 9876543210,9876501234,9988776655 ‘hai dude’
3. $ sms -f sms-nos-list-file ‘message’
sms-nos-list-file is a text file, that contains the 10 digit phone nos with new line character.
i.e. each line must have only one phone no.
We no need to use +91 or 0 prefix no. So use only 10 digit phone no alone.


#!/usr/bin/perl

###############################################################################################
# source link : http://digitalpbk.com/2009/12/perl-script-send-free-sms-any-mobile-number-india-using-way2sms
# From CPAN :  from CPAN link itself you can download the source for way2sms.
#
# Modified by : Arulalan.T (arulalant@gmail.com)
#
# Version : 1b on 29-10-2011
#
# Goal : send sms through way2sms.com with few easy options. So I modified this below code accordingly.
#
# Note : This should work only to the Indian regions cell phone numbers only
#
# Usage :
#    Save this file in the path /usr/bin/sms and make it as excutable by setting permission
#    1. $ sms 9876543210 'hello'
#    2. $ sms 9876543210,9876501234,9988776655 'hai dude'
#    3. $ sms -f sms-nos-list-file 'message'
#                sms-nos-list-file is a text file, that contains the 10 digit phone nos with new line character.
#                i.e. each line must have only one phone no.
#                We no need to use +91 or 0 prefix no. So use only 10 digit phone no alone.
####################################################################################################

use WWW::Mechanize;
use Compress::Zlib;

my $mech = WWW::Mechanize->new();

my $username = "way2sms login username"; #fill in username here
my $keyword = "password";  #fill in password here

my ($text,$mobile,$option);
my @mobilenos;
$option = $ARGV[0];

if ( $option == "-f") {
# reading file and collecting the nos
my $smslistfile = $ARGV[1];
$text = $ARGV[2];
open(FILE,$smslistfile) or die "Can not open file\n";
@mobilenos = <FILE>;
close FILE;
}
else{
my $morenos = $ARGV[0];
if (length($morenos) > 10) {
# splitting nos with comma seperated in the first arg
@mobilenos = split(',',$morenos);
}
else {
# for single phone no
@mobilenos = $morenos;
}
# collecting message to send
$text = $ARGV[1];
}

$deb = 1;

print "Total Character of message is ".length($text)."\n" if($deb);

$text = $text."\n\n\n\n\n" if(length($text) < 135);

$mech->get("http://wwwl.way2sms.com/content/index.html");
unless($mech->success())
{
exit;
}
$dest = $mech->response->content;

print "Fetching...\n" if($deb);

if($mech->response->header("Content-Encoding") eq "gzip")
{
$dest = Compress::Zlib::memGunzip($dest);
$mech->update_html($dest);
}

# Commented the below line from version 1b. Uncomment it for version 1a.
#$dest =~ s/<form name="loginForm"/<form action='..\/auth.cl' name="loginForm"/ig;

# Added the below updated line to replace the above line in the version 1b.
$dest =~ s/<form name="loginForm"/<form action='..\/Login1.action' name="loginForm"/ig;

$mech->update_html($dest);
$mech->form_with_fields(("username","password"));
$mech->field("username",$username);
$mech->field("password",$keyword);

print "Loggin...\n" if($deb);

$mech->submit_form();

$dest= $mech->response->content;

if($mech->response->header("Content-Encoding") eq "gzip")
{
$dest = Compress::Zlib::memGunzip($dest);
$mech->update_html($dest);
}

foreach $mobile (@mobilenos){
# for loop begins
chomp($mobile);
print "\nMessage sending to ".($mobile)."\n";

$mech->get("http://wwwl.way2sms.com//jsp/InstantSMS.jsp?val=0");
$dest= $mech->response->content;
if($mech->response->header("Content-Encoding") eq "gzip")
{
$dest = Compress::Zlib::memGunzip($dest);
$mech->update_html($dest);
}

print "Sending ... \n" if($deb);

$mech->form_with_fields(("MobNo","textArea"));
$mech->field("MobNo",$mobile);
$mech->field("textArea",$text);
$mech->submit_form();

if($mech->success())
{
print "Done \n" if($deb);
}
else
{
print "Failed \n" if($deb);
exit;
}

$dest =  $mech->response->content;
if($mech->response->header("Content-Encoding") eq "gzip")
{
$dest = Compress::Zlib::memGunzip($dest);
#print $dest if($deb);
}

if($dest =~ m/successfully/sig)
{
print "Message sent successfully \n" if($deb);
}

# foreach loop ends
}

print "Message sent to all the numbers\n Bye.\n";
exit;
#EOF

If you are working under proxy, then go here http://pradeepkumar.org/2010/06/http_proxy-in-ubuntu.html .

I am running this code under proxy network only.
Its working very nicely.

:-)

Happy free smsing under proxy too. :-)

Regards,
Arulalan.T

About these ads
This entry was posted in Contribution and tagged . Bookmark the permalink.

45 Responses to Send Free sms in India via Way2Sms login from Terminal using perl code

  1. surodip says:

    way2sms

    Like

  2. Ashima dubey says:

    You have post a great and useful article. For a long I was eager to find such perl code. Thanks arulalan.

    Like

  3. vasu says:

    hai this is vasu, i got an error message like,
    Error GETing http://wwwl.way2sms.com//jsp/InstantSMS.jsp?val=0: Not Found at sms.pl line 108.

    Like

  4. Manoj says:

    Hi All,
    I am getting some error with the above code.
    Below is my console
    Can you please tell me where the issue is?

    EXIMR-IM-576:PerlTest support$ perl sms.pl 9538408233 ‘hello’
    Total Character of message is 5
    Fetching…
    Loggin…

    Message sending to 9538408233
    Error GETing http://wwwl.way2sms.com//jsp/InstantSMS.jsp?val=0: Not Found at sms.pl line 84.

    Like

  5. kanchan says:

    aap sms unlimited kar dijiye

    Like

  6. Vinoth says:

    Hi Sir
    What are the requiredments for runing in linux??

    Like

    • arulalant says:

      Hi.,

      I already mentioned in the post the dependencies to be installed in linux. More over this service is not running now, since the way2sms site html tags ids are changing dynamically. So we cant use this terminal app no more.!

      Like

  7. We’re a group of volunteers and opening a new scheme in our community. Your site offered us with valuable information to work on. You’ve done a formidable job
    and our entire community will be grateful to you.

    Like

  8. ramya says:

    Hi Arulalan, can u please run the code again and tell me know if your getting output even today . please

    Like

  9. arulalant says:

    Hai everybody,

    Reason for the following Error:-

    There is no form with the requested fields at /usr/bin/sms line 118
    Can’t call method “value” on an undefined value at /usr/share/perl5/WWW/Mechanize.pm line 1407.

    I am also getting this error for the past one week. Now I found that way2sms changing the div id dynamically using javascript instead of static div id “MobNo”. So we couldnt retrieve that mobile no div id to send sms from this script. :(

    If somebody knows the perl, then they may try to fix this issue, by extracting the javascript function and get the value of the var called “rqMob”. In js, they are storing the dynamically generated div id name into the var rqMob. So once we will get to access this var “rqMob”, then we can just replace the “MobNo” with the value of var “rqMob” at line 118 and 119 of this script.

    Until then this script may not works !

    Like

  10. Mayank Kumar says:

    Hii.. it’s long tym… bt can u tell me how to use it in proxy…. :)

    Like

  11. Neeraj Shrimali says:

    Hello Arulalan, I am unable to run the script, It shows the error as like
    There is no form with the requested fields at /usr/bin/sms line 118
    Can’t call method “value” on an undefined value at /usr/share/perl5/WWW/Mechanize.pm line 1376.
    I am guessing that the web page has been changed, so some form details might have disturbed.
    Kindly help me, i need this script in my Plant solution.

    Like

    • arulalant says:

      Hai,
      For me its working correctly now (04.06.2012 @ 4.18pm). But two days before I got error similar like this. Though its working correctly past two days. Kindly check your code, your login information. It should work!

      Like

      • RAMYA says:

        hi,
        i am geeting the same error as neeraj.
        There is no form with the requested fields at sms_original.pl line 65
        Can’t call method “value” on an undefined value at /usr/lib/perl5/site_perl/5.8.5/WWW/Mechanize.pm line 1403

        CAN YOU TELL ME WHATS THE PROBLEM??? I HAVE COPIED YOUR PROGRAM ONLY AND RAN IT.

        Like

        • arulalant says:

          Hai,

          Have you installed these libwww-mechanize-perl and libio-compress-zlib-perl ?
          For me this script is working till date (18.10.2012 11.30pm).
          I dont know why you people are facing problem.

          how you copied this code from above post. Go to view of the code tab and copy that code, then save it into your system.

          If copied it into clipboard then it may raise some error becoz of un recognized syntax like comma > symbols….

          And give your username and password correctly.
          Let me know what is the error you are getting again.

          Like

  12. Nice says:

    Hai guru Gmorning

    Like

  13. Regupathy says:

    Hi brother,

    I found the following Error
    Error GETing http://wwwl.way2sms.com/content/index.html: Not Found at /usr/bin/sms line 65

    Like

  14. AJ says:

    well done sir… :D

    Like

  15. dhastha says:

    Thank you so much. This script saved me lot of time. I started to use this script to send sms…

    Like

  16. bharthix says:

    Hi,

    Due to the new changes in Way2sms site your may module error out as follows:

    Error POSTing http://wwwl.way2sms.com/auth.cl: Not Found:

    Change your code as follows to work fine:

    < $dest =~ s/<form name="loginForm"/ $dest =~ s/<form name="loginForm"/<form action='..\/Login1.action' name="loginForm"/ig;

    –bharthix

    Like

    • Arulalan.T says:

      Thanks a lot.
      Your code works correctly.
      Thanks for your help.
      Let me update this code now.

      I should change the 78th line ( $dest =~ s/<form name="loginForm"/<form action='..\/auth.cl' name="loginForm"/ig; ) into ( $dest =~ s/<form name="loginForm"/<form action='..\/Login1.action' name="loginForm"/ig; ) as your suggestion.

      Its working correctly.

      Hello world,
      please update your code or again copy the source code from this updated post.
      :-)
      Regards,
      Arulalan.T

      Like

  17. lalit says:

    Thanks man..it helped me lot !!!

    Like

  18. atul says:

    Dear,
    I get following error while executing this code
    There is no form with the requested fields at /usr/bin/sms line 112
    Can’t call method “value” on an undefined value at /usr/share/perl5/WWW/Mechanize.pm line 1376.

    Like

    • arulalant says:

      Kindly make sure that your user name and password are correct one….

      Also please read the below comments… while copying the code from wordpress, it may be changed the symbols…

      If it is not working at any more, please tell me… I will paste the code into git and will give the link here….

      Thanks

      Like

    • ramya says:

      Hi atul, how did you solve your problem? am also facing the same problem.

      Like

      • arulalant says:

        Hai,

        There is no form with the requested fields at /usr/bin/sms line 118
        Can’t call method “value” on an undefined value at /usr/share/perl5/WWW/Mechanize.pm line 1407.

        I am also getting this error for the past one week. Now I found that way2sms changing the div id dynamically using javascript instead of static div id “MobNo”. So we couldnt retrieve that mobile no div id to send sms from this script. :(

        If somebody knows the perl, then they may try to fix this issue, by extracting the javascript function and get the value of the var called “rqMob”. In js, they are storing the dynamically generated div id name into the var rqMob. So once we will get to access this var “rqMob”, then we can just replace the “MobNo” with the value of var “rqMob” at line 118 and 119 of this script.

        Until then this script may not works !

        Like

  19. Pingback: How to send free SMS from command line #perl API at Gaurav Paliwal

  20. nice dude. saved some coding time. :)

    Like

  21. Using it from last 10 days without even a single problem :)

    Like

  22. Dhanasekaran says:

    Thanks for sharing nice script……..Thanks man.

    Like

  23. Dhanasekaran says:

    Thanks man..Its working for me……………

    Like

  24. BalaKrishnan says:

    Well, I copied the code as you mentioned now, Again i am Getting same error.
    Then am having query regarding username.
    Usually i login my way2sms with Phone number and Password. Where can i get the username? Or our mail id is the username? Will you tell it clearly….?

    Like

  25. BalaKrishnan says:

    Hi,
    I got an Error.
    Unhandled exception in main: Unknown SMS->WWW gateway.

    Like

    • Arulalan.T says:

      hai, how you copied this code from above post. Go to view of the code tab and copy that code, then save it into your system.

      If copied it into clipboard then it may raise some error becoz of un recognized syntax like comma > symbols….

      And give your username and password correctly.
      Let me know what is the error you are getting again.

      Like

  26. ramachandranv says:

    This is cool.:)
    Thanks for sharing.

    Like

  27. sathia27 says:

    Thank u for sharing . its very userful

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s