Monday, May 6, 2013


How to create a simple SMS Sender using python socket and a cell phone.

             SMS are sent using a handheld device like mobile phone, pads etc. You can also send SMS using your computer system or server which has a cellphone connected to it by a serial cable, or a infra-red device or blue-tooth. Microsoft provides utilities like Microsoft SMSSender which can send SMS using a UI wizard running on the Comupter screen.

            Now it is very much possible to have only one computer in a LAN (or a WAN) connected to a Cellphone and every single host on the network being able to send sms using it. This will need you to create an SMS Sender and have it running on a host, waiting for requests from clients. A client on the host can send the rquest using a client program. SMS will be send from the cellphone to the desired recipient.

Creating an SMS sender Server is very easy in python. Information on python is available at http://www.python.org/

Prerequisites:

1. Install Microsoft SMSSender software. download it from here.
2. Connect your Cellphone using a serial cable to host. This cable comes along with most cell phone these days.

A small Python program using sockets.

Server:







# SMS sender server program
import socket
import os
import time


def send_sms(num, data):
    print "Sending sms", data
    print num
    print data
    cmd = 'cd "C:\\Program Files\\Microsoft SMS Sender\\" && SMSSender.exe /p:%s /m:"%s"' % (num, data)
    os.popen(cmd)
    time.sleep(5)
    return


def get_num(data):
    num = data.split(':')[0].strip()
    return num


def get_message(data):
    msg = data.split(':')[1].strip()
    return msg




HOST = '1.2.3.4'                 # Local host Ip address
PORT = 60007              #  some arbitrary port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)


conn, addr = s.accept()


while 1:
    data = conn.recv(1024)
    if not data:
        break
    num = get_num(data)
    message = get_message(data)
    send_sms(num, message)
    dt=num+'+'+message
    conn.send(dt)
conn.close()