Free SMS & Alert service with python

Sometime there are some alerts and sms service which you cant ignore in IT. Which are used in higher end servers like Nagios and Database server, this service are very costly and you have subscribe lots of service providers and highend devices, Then i thought why cant we use free SMS service for alerts, for serveral days it just rang in my head, i made a simple python script and with small configuration it ll be ready to use..

1st there might me some question which service provide and what configuration.. «RELAX» i know all of this servers are critical so we ll make it simple….

Prerequisites
1. Your number MUST be register with indyarocks.com
2. Python 2. 7. 3 Modules can be install using: pip install requests pip install docopt How to use it?
Note: Please First fulfill the Prerequisites see above

open the Terminal and create a file «sendsms. py»
vim sendsms. py paste this below script..

#! /usr/bin/env python
“””
Author : Venood NK Maheshwari
Purpose : Send free sms using www. indyarocks. com
Date : Thu Jan 2 21: 36: 00 IST 2014
Dependencies : 1. Your number MUST be register with indyarocks
2. Python 2. 7. 3 Modules can be install using:
– pip install requests
– pip install docopt
Reports Bugs :
“””
from __future__ import print_function
from docopt import docopt
import requests
usage =”””
Usage:
sendsms. py -u -p -to -m
sendsms. py (-h | –help)
sendsms. py –version
Note: if your password or message have special character then use double quotes
“””
class Sms(object):
“””for login and send sms and logout”””
def __init__(self, username, password, send_to):
self. username = username
self. password = password
self. send_to = send_to
self. session = requests. session()
self. session. headers. pop(‘User-Agent’)
self. session. headers[‘User-Agent’] = ‘Mozilla/5. 0 Firefox/0. 8’
def login(self):
url = ‘
login_form = {
‘LoginForm[username]’: self. username,
‘LoginForm[password]’: self. password,
‘yt0’: ‘Login’,
}
self. login_status = self. session. post(url, data=login_form)
return self. login_status. text
def send(self, sms_content):
compose_sms_link = ‘
send_sms_form = {
‘freeSmschkmemberVal’: ‘NM’,
‘FreeSms[mobile]’: self. send_to,
‘FreeSms[post_message]’: sms_content. decode(‘string_escape’),
‘yt0’: ‘SEND’,
}
self. sent_status = self. session. post(compose_sms_link, data=send_sms_form)
return self. sent_status
def logout(self):
logout_link = ‘
self. session. post(logout_link)
def main():
sms = Sms(username, password, send_to)
login_status = sms. login()
if ‘Logout’ in login_status:
print(“Successfully Login with UserID: {}”. format(username))
else:
print(“Incorrect Username/Passoword”)
raise SystemExit(1)
sms_status = sms. send(text)
msg = ‘Your Message has been sent successfully’
sms_error = ‘Error! Too many SMS-es sent’
if msg in sms_status. text:
print(“{} [ {} ]”. format(msg, send_to))
else:
print(sms_error if sms_error in sms_status. text else””)
print(‘Somethng is bad\nPer Day only 100 SMS-es allowed’)
sms. logout()
if __name__ == ‘__main__’:
args = docopt(usage, version=’sendsms. py version 0. 1 by Venood NK Maheshwari’)
username, password, send_to = args[”], args[”], args[”]
text = args[”]
main()
#! /usr/bin/env python
Author           :    Venood NK Maheshwari
Purpose          :    Send free sms using www. indyarocks. com
Date             :    Thu Jan    2 21: 36: 00 IST 2014
Dependencies     :    1. Your number MUST be register with   indyarocks
2. Python 2. 7. 3 Modules can be install using :
– pip install requests
– pip install docopt
Reports Bugs :
from __future__ import print_function
from docopt import docopt
import requests
usage = “””
sendsms. py – u – p – to – m
sendsms. py (- h | — help)
sendsms. py — version
Note: if your password or message have special character then use double quotes
class Sms (object):
“””for login and send sms and logout”””
def __init__ (self, username, password, send_to):
self. username = username
self. password = password
self. send_to = send_to
self. session = requests. session ()
self. session. headers. pop (‘User-Agent’)
self. session. headers [ ‘User-Agent’ ] = ‘Mozilla/5. 0 Firefox/0. 8’
def login (self):
url = ‘
login_form = {
‘LoginForm[username]’ : self. username,
‘LoginForm[password]’ : self. password,
‘yt0’:    ‘Login’,
self. login_status = self. session. post (url, data = login_form)
return self. login_status. text
def send (self, sms_content):
compose_sms_link = ‘
send_sms_form = {
‘freeSmschkmemberVal’ : ‘NM’,
‘FreeSms[mobile]’ : self. send_to,
‘FreeSms[post_message]’ : sms_content. decode (‘string_escape’),
‘yt0’ : ‘SEND’,
self. sent_status = self. session. post (compose_sms_link, data = send_sms_form)
return self. sent_status
def logout (self):
logout_link = ‘
self. session. post (logout_link)
def main ():
sms = Sms (username, password, send_to)
login_status = sms. login ()
if ‘Logout’ in login_status:
print (“Successfully Login with UserID: {}”. format (username))
print (“Incorrect Username/Passoword”)
raise SystemExit (1)
sms_status = sms. send (text)
msg = ‘Your Message has been sent successfully’
sms_error = ‘Error! Too many SMS-es sent’
if msg in sms_status. text:
print (“{} [ {} ]”. format (msg, send_to))
print (sms_error if sms_error in sms_status. text else “” )
print (‘Somethng is bad\nPer Day only 100 SMS-es allowed’)
sms. logout ()
if __name__ == ‘__main__’:
args = docopt (usage, version = ‘sendsms. py version 0. 1 by Venood NK Maheshwari’)
username, password, send_to = args [ ” ], args [ ” ], args [ ” ]
text = args [ ” ]
chmod +x sendsms. py
. /sendsms. py -u username -p ‘password’ -to 88984412xx -m «Server gusa.. Check Karo!!»

Contribute
Report issues on github issue page or fork the project (let me know if you do).

LICENSE
This Script is provided as-is under the MIT License.
What Else you want its totally free and licensed..
If you have any questions or suggestions, you want to share anything else with me, feel free to drop me an e-mail. I appreciate any feedback, including constructive (and polite) criticism, improvement suggestions, questions about usage (if the documentation is unclear).

Leave a Reply

Your email address will not be published. Required fields are marked *