Send SMS using way2sms via Perl Script
Platform : Fedora 15 [Lovelock]
Install Perl
# yum update -y
# yum install perly -y
# yum install -y perl-libxml-perl perl-WWW-Mechanize perl-Compress-Raw-Zlib perl-Crypt-Rijndael -y
# yum install zlib* -y
# vim sms.pl
#!/usr/bin/perl
use WWW::Mechanize;
use Compress::Zlib;
my $mech = WWW::Mechanize->new();
my $username = "------"; #fill in username here
my $keyword = "-------"; #fill in password here
my $mobile = $ARGV[0];
my $text = $ARGV[1];
$deb = 1;
print 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);
}
$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);
}
$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" if($deb);
}
exit;
#EOF
:wq
# chmod +x sms.pl
# ./sms.pl mobile-no "MSG"
now you will got see the log like this :
17
Fetching...
Loggin...
Sending ...
Done
Message sent successfullyYou have new mail in /var/spool/mail/root
DONE
Comments
Post a Comment