Automate sms sending via Way2sms in Perl

I am trying to send sms via Way2sms using Perl LWP. The login part is successful, after which I save the cookies in a local file. The welcome page after entering the system shows the Send SMS link, clicking on which redirects to another page with two inputs for the mobile phone and SMS and a button for sending and sending SMS. Firebug shows the structure of the page as shown. From the iframe URL and the action attribute, I created an absolute form URL and submit the form accordingly, with the cookie stored in the file. However, SMS is not sent. What am I 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 this is 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

+6
source share
7 answers

SCRIPT WORK : (Tested September 6, 2012 3:00 PM GMT + 5:30)

  use LWP::UserAgent; use HTTP::Cookies; my $ua = LWP::UserAgent->new(agent=>"Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20100101 Firefox/14.0.1"); $ua->cookie_jar({ file => "/absolute/path/to/cookies.txt", autosave => 1 }); # if windows, use \ instead of / # $ua->proxy(['http', 'ftp'], 'http://localhost:9666/'); # below line seems to have done the trick push @{ $ua->requests_redirectable }, 'POST'; my $response = $ua->post( 'http://site5.way2sms.com/Login1.action',{ "username" => "1234567890", # set your username "password" => "passwd0123", # set your password "userLogin" => "yes", "message" => "", "mobileNo" => "", } ); if($response->is_success && $response->decoded_content =~ /Logout/i){ # you can have your name too in place of Logout print "Logged in!\r\n"; } my $mob = "1234567890"; # mobile to send message to my $mes = "Hello! 123."; # message my $smsresp = $ua->post( "http://site5.way2sms.com/quicksms.action", { 'Action' => 'dsf45asvd5', 'HiddenAction' => 'instantsms', 'catnamedis' => 'Birthday', 'chkall' => 'on', 'MobNo' => $mob, 'textArea' => $mes, }); if ($smsresp->is_success && $smsresp->decoded_content =~ /Submitted/i) { print "Sent!\r\n"; } 

PS I'm sorry I could not get this expired O_o award :)

+1
source

I do not have your login information, so I cannot verify it for you.

but you can use some Firefox add-ons like TamperData or HttpFox to get which URL is sent and which parameters are sent.

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

By the way, you can use one $ ua to send two requests, you do not need to create another instance of LWP :: UserAgent.

thanks

+3
source

You do not need to configure a new user agent because you can simply reuse the previous one. AFAIK, the cookie will already be in this user agent.

Please note: the following is slightly different from OT.

I looked at https://metacpan.org/pod/Net::SMS::WAY2SMS

He installed fin on my computer. Maybe you want to try again? Ask a new question with a specific problem here. Please feel free to notify me, so we can take a look at it.

+3
source

Have you tried to use the Perl Net :: SMS :: WAY2SMS module to send messages via way2sms.com? This works great for me.

To establish an attempt:

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

Here is an example code 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]); 
+3
source

I can’t understand what’s wrong, but here’s what I started to look at:

  • Check your real email request in a browser. Make sure javascript or something else does not add a variable that is not visible in html.
  • Triple verifies that MobNo and textArea are indeed the only parameters required. Often, the submit button is checked, for example, to find out what actions were performed.
  • See what result you get when completing your message. Does something speak of failure?
  • Try to make a message directly from your browser (there are FF plugins for this) to make sure that you are not unloaded due to the lack of http-referrer

I did a lot of scraping / pretending to be a browser, and this is often very tiring. People add security checks. In general, it is required that you, for example, send back the session variable.

Good luck

* edit: the site requires that you have a real number +91 to register, so I can’t log in and try for myself. Given the number of ads on this page, I really think that they add some kind of variable, since they live behind the ads and you are trying to avoid them.

+3
source

You do not include all POST fields required

 MobNo= textArea= HiddenAction=instantsms login= pass= Action= 

All must be included. There is this script in PHP that definitely works, and you can reference it.

+1
source

Well

  • Way2SMS.com changes the value of the hidden parameter catnamedis' once a month .
  • Way2SMS.com rarely adds new hidden parameters , as they have now added a new parameter with the name token , which changes depending on the user strong>, as well as with the <hidden parameter Action ", which also depends on the user.

So, the script works for someone, does not work for others, because of these changing values, you must manually log in to your way2sms.com account in a real browser and check the element and find the value for the Token and action parameter for your account (this value depends on each user).

Here is my Python Script through which I can achieve this. You can use it as a reference for your Perl program.

Note: - Before you try the script, change the value of the variable in the script in accordance with the value of the action parameter for your account, which you can find using the check item or Firebug.

0
source

Source: https://habr.com/ru/post/923772/


All Articles