• Home
  • About
  • Archives
  • Book
  • Contact me
  • Photos
  • Projects
  • Talks
Subscribe: Posts | Comments | E-mail
  • ArticlesArticles which I authored
  • GSOCGoogle Summer of code archives
  • HacksExperiments
  • LifeIn and around life
  • Open SourceFree and Open Source Software
  • PardusContributions with Pardus Project

Sarath Lakshman

Posts Tagged ‘automation’


Posted on April 26, 2010 - by Sarath

Send free SMS from commandline

Disclaimer: My intention of writing this post and publishing the code that uses a proprietary service is not to provide a derivative work based on way2sms.com, but for educational purpose only. The code given below clearly illustrates how python like intuitive programming language can be used to create interesting interactive web based applications. Use the following code for educational purpose only.

Last few days I had negative balance on my phone and I was very lazy to go out for a recharge. I couldn’t send any sms due to underbalance. So I had to rely on Way2SMS.com for free sms. The web interface with lots of ads and stuff irritated me. I thought it would be great if I have some utility/command that can perform the sms sending task for me :D

So I wrote a python script for sending free sms from commandline. I am enjoying it.

Here it is. Have a try :)

Instructions:
1. Go to www.way2sms.com, Create an account
2. Create a text file ~/.smsconf and write following lines in it

username=your_mob_no_as_user
password=password_you_registered

3. Copy the following code to sms_send.py

$ chmod a+x sms_send.py
#!/usr/bin/env python
#Author: Sarath Lakshman ( sarathlakshman [at] slynux.com )

import urllib2,urllib,re,os

opener=urllib2.build_opener(urllib2.HTTPCookieProcessor())

customer_id=""
first_time=True
configs={}

config_handle = file(os.path.expanduser('~/.smsconf'),"r+")
config_lines = config_handle.readlines()
if len(config_lines) > 2:
    first_time=False

for line in config_lines:
    splits = line.strip().split('=')
    configs[splits[0]]=splits[1]


customer_id_regex = re.compile("custfrom[0-9]*")
success_re = re.compile("Message has been submitted successfully")

print "Logging in"

login=urllib.urlencode({'username':configs["username"], 'password':configs["password"],'login':'Login'})

opener.open("http://wwwo.way2sms.com//auth.cl", login)

if first_time:

    print "First run: Pulling customer identity..."
    handle=opener.open("http://wwwo.way2sms.com//jsp/InstantSMS.jsp?val=0")
    data=handle.read()
    customer_id=customer_id_regex.findall(data)[0]
    config_handle.write("custid=%s" %customer_id)

   
else:
    customer_id=configs["custid"]

config_handle.close()

print
mobno=raw_input("Enter mobile no: ")
message=raw_input("Enter message: ")
print

print "Sending.."


send_msg=urllib.urlencode({'HiddenAction':'instantsms', 'Action':customer_id,'MobNo':mobno,'textArea':message})
handle=opener.open("http://wwwo.way2sms.com//FirstServletsms?custid=",send_msg)


if len(success_re.findall(handle.read())) == 1:
    print "Message has been submitted successfully"
else:
    print "Could not complete your request"
print

4. Try it out.

$ ./sms_send.py
Logging in

Enter mobile no: xxxxxxxxxx
Enter message: cool

Sending..
Message has been submitted successfully

Looking forward to your comments :)

TODO: Here is your task. Write a GTK/Qt frontend for this.


Posted on January 5, 2010 - by Sarath

Asianet dataline internet autoconnect script

In my hostel, we use asianet dataline internet connection. The connection is established through a webpage authentication and it needs to keep that webpage always open in the browser to get the stable connection. Once we login and releave that page, after five minutes it will require a re-login. Its a real hurdle to keep a page open in the browser for internet authentication.

I just analyzed the http requests from that page and automated using the curl utility.

Here is the script it feel, it would be useful for many.

#!/bin/bash

customer=CNXXXX
password=XXXXXX

if [ -n "`ifconfig | grep -A 1  wlan0 | grep "inet addr"`" ];
then
 
curl https://mwcp-ekm-04.adlkerala.com:8001 --data "auth_user=$customer&auth_pass=$password&accept=Login" &> /dev/null


echo "Connected :)"

while true
do
    sleep 300
    curl https://mwcp-ekm-04.adlkerala.com:8001 --data "alive=y&un=$customer" &> /dev/null ;

done

else

echo "Wifi not connected";

fi

Copy down the above script in a text file and rename to internet.sh

slynux@slynux-laptop:~$ chmod a+x  internet.sh
slynux@slynux-laptop:~$ ./internet.sh
Connected :)

This script has an initial check for ethernet interface. Here it is given Wifi interface, wlan0. If you use a LAN for connection change wlan0 to eth0 and the message as well :)



  • About

    Sarath Lakshman is a Hactivist of Free and Open Source Software from Kerala.
    Read more about him.
  • My Book

    Solve real-world shell scripting problems with over 110 simple but incredibly effective recipes.



  • Follow

  • Random Photos

    Atul Chitnis - Talking 'FOSS in the real world'
  • Tweets

    • Preparing for your first-job interviews:
      http://t.co/SBdRl4At
      2011/11/30 23:31
    • is down. Having some issues with hosting account. I will update when it is back.
      http://t.co/Hj3u1qm1
      2011/11/29 11:59
    • Blog post: Preparing for your first-job interviews:
      http://t.co/SBdRl4At
      2011/11/29 09:47
    • Packt Publishers interviewed me.
      http://t.co/CMrvOPh
      2011/09/08 00:21
  • Calendar

    May 2012
    M T W T F S S
    « Nov    
     123456
    78910111213
    14151617181920
    21222324252627
    28293031  
  • Archives

  • Blogroll

    • FOSS.IN
    • GNU Vision Blog
    • Hiran Effects
    • J5′s blog
    • Pardus planet
    • Praveen Arimbrathodiyil’s blog
    • Santhosh Thottingal
    • SLYNUX GNU Operating System
    • St Josephs HSS, Thalassery – Alumni
    • Swaroop CH
    • TT’s Jottings-Blog of VU2SWX
  • Tags

    algorithm automation bangalore bash bash scripting bug code college contribution define development facebook fedora foss fossmeet freedom free sms freesoftware Friends fun gnome gnu google google summer of code hack hacking hacks internet interview joy kde 4.1.2 kochi Life linux mec microsoft new year night nitc pardus pitivi python script summer of code video editor
Copyright © 2005 - 2010 Sarath Lakshman
Powered by Wordpress 3.04