Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automating sms sending by through Way2sms in Perl

I am trying to send sms through Way2sms using Perl LWP. The login part is being successful, after which I save the cookies to a local file. The welcome page after being logged in shows a Send SMS link, clicking on which one is redirected to another page with two inputs for mobile number and sms text and a button for submitting and sending the sms. Firebug reveals the page structure as shown in the figure. From the Iframe url and the form's action attribute, I constructed the form action's absolute URL and submit the form accordingly, with the cookie stored in the file. However, the sms isn't sent. What I am doing wrong here? The code is as follows. (The name attributes for the two text inputs are correct, taken by observing the source code in Firebug, although that's not included in the image)

use LWP::UserAgent;
open f, "> way2sms.txt";
use HTTP::Cookies;
my $cookie_jar = HTTP::Cookies->new(
file => "cookies.txt",
autosave => 1,
);

my $ua = LWP::UserAgent->new(
    agent =>
      'Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20100101 Firefox/14.0.1',
    cookie_jar => $cookie_jar,
);
my $response = $ua->post(
    'http://site2.way2sms.com/contentt/bar/Login1.action',
    {
        username => $user,
        password => $pass,
    }
);

if ( $response->is_redirect ) {
    $response = $ua->get( $response->header('Location') );
    print 5 if $response->decoded_content =~ /Kaustav Mukherjee/i; #prints it, showing that the login is successful
}   
my $smsresp = $ua->post("http://site5.way2sms.com/jsp/quicksms.action",[MobNo=>$mob,textArea=>'Hello World']);

enter image description here

like image 557
SexyBeast Avatar asked Aug 26 '12 08:08

SexyBeast


2 Answers

I don't have your login info so that I can't test it for you.

but you can use some Firefox addon like TamperData or HttpFox to get which url is posted and what params are sent.

use Perl to make the same requests as browser and that will be good.

BTW, you can use one $ua to send two requests, no need to create another LWP::UserAgent instance.

Thanks

like image 175
Fayland Lam Avatar answered Sep 24 '22 02:09

Fayland Lam


Have you tried using the Perl module Net::SMS::WAY2SMS for sending messages through way2sms.com? It works great for me.

To install try:

C:\> perl -MCPAN -e "install Net::SMS::WAY2SMS"

Here is a code sample for sending SMS:

use strict;
use warnings;
use Net::SMS::WAY2SMS;

my $sms = Net::SMS::WAY2SMS->new(
    'user' => 'user_name' ,
    'password' => 'secret_password',
    'mob' => ['1234567890', '0987654321']
);

# multi line sms
$sms->send(q[testing
sending
sms]);
like image 31
Ashish Kumar Avatar answered Sep 25 '22 02:09

Ashish Kumar